-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
34 lines (29 loc) · 989 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
import datetime
from pymongo import MongoClient
connectionString="mongodb+srv://admin:[email protected]/<dbname>?retryWrites=true&w=majority"
client = MongoClient(connectionString)
db=client.scraped
authors = db.authors
def queryDatabase(search_param):
result = authors.find_one({ 'full_name' : search_param }, {'_id':False} )
if(result is not None):
return result
else:
return None
def insertData(name, data):
if(queryDatabase(name) is not None):
authors.replace_one({ 'full_name' : name }, {
'full_name' : name,
'date' : datetime.datetime.now(),
'microsoft' : data['microsoft'],
'google' : data['google']
})
else:
authors.insert_one({
'full_name' : name,
'date' : datetime.datetime.now(),
'microsoft' : data['microsoft'],
'google' : data['google']
})
insertedData = queryDatabase(name)
return insertedData