forked from MRK-YT/RENAMER_BOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
36 lines (30 loc) · 836 Bytes
/
database.py
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
33
34
35
36
import pymongo
import os
DB_NAME = os.environ.get("DB_NAME","")
DB_URL = os.environ.get("DB_URL","")
mongo = pymongo.MongoClient(DB_URL)
db = mongo[DB_NAME]
dbcol = db["user"]
def insert(chat_id):
user_id = int(chat_id)
user_det = {"_id":user_id,"file_id":None}
try:
dbcol.insert_one(user_det)
except:
pass
def addthumb(chat_id, file_id):
dbcol.update_one({"_id":chat_id},{"$set":{"file_id":file_id}})
def delthumb(chat_id):
dbcol.update_one({"_id":chat_id},{"$set":{"file_id":None}})
def find(chat_id):
id = {"_id":chat_id}
x = dbcol.find(id)
for i in x:
lgcd = i["file_id"]
return lgcd
def getid():
values = []
for key in dbcol.find():
id = key["_id"]
values.append((id))
return values