-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
42 lines (29 loc) · 1.15 KB
/
database.py
File metadata and controls
42 lines (29 loc) · 1.15 KB
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
37
38
39
40
41
42
from datetime import datetime
from pymongo import MongoClient
class Mongo():
def __init__(self, db="savelink", collection="mycollection"):
self.__client = MongoClient()
self.__db = self.__client[db]
self.__collection = self.__db[collection]
def Insert(self, title, lang, link):
data = {
"title": title,
"lang": lang,
"link": link,
"created_date": datetime.now()
}
self.__collection.insert(data)
def get_all(self):
return list(self.__collection.find())
def get_query(self, **kwargs):
if "title" and "link" and "lang" in kwargs:
return self.__collection.find({"title": kwargs["title"],
"link": kwargs["link"],
"lang": kwargs["lang"]})
def delete_query(self, **kwargs):
if "title" in kwargs:
self.__collection.delete_many({"title": kwargs["title"]})
elif "link" in kwargs:
self.__collection.delete_many({"link": kwargs["link"]})
else:
raise BaseException("Add link or title")