-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabaseHandle.py
More file actions
32 lines (27 loc) · 878 Bytes
/
databaseHandle.py
File metadata and controls
32 lines (27 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pymongo
import time
import os
from dotenv import load_dotenv
load_dotenv()
DBclient = os.getenv("CLIENT")
class Database():
def __init__(self):
self.client = None
self.connected = False
def connectDB(self):
if not self.connected:
try:
self.client = pymongo.MongoClient(DBclient, serverSelectionTimeoutMS=3000)
self.connected = True
except Exception as e:
print("connectDB [Error]: " + str(e))
time.sleep(10)
return self.connectDB()
def getVideo(self, username, id):
self.connectDB()
db = self.client.TikTok.bae.find_one({'id':'tiktok'})
try:
return db['videos'][str(username)][str(id)]
except Exception as e:
print("getVideo [Error]: " + str(e))
return None