-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_operations.py
30 lines (26 loc) · 964 Bytes
/
db_operations.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
def filterWithUrl(url,collection):
query={"url":url}
item=collection.find(query)
for i in item:
return i
def addItem(data, collection):
try:
existingData=filterWithUrl(data["url"],collection)
latestTime=list(data.keys())
latestTime.remove('url')
latestTime.remove('asin')
latestTime=latestTime[0]
if existingData==None:
var=collection.insert_one(data)
collection.update_one({"url":data["url"]},{"$set":{"latest":latestTime}})
return True
else:
existingData[latestTime]=data[latestTime]
collection.update_one({"url":data["url"]},{"$set":{latestTime:data[latestTime]}})
collection.update_one({"url":data["url"]},{"$set":{"latest":latestTime}})
return True
except:
return False
def deleteWithUrl(url,collection):
query={"url":url}
collection.delete_one(query)