-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmongo.py
More file actions
52 lines (43 loc) · 1.44 KB
/
mongo.py
File metadata and controls
52 lines (43 loc) · 1.44 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
43
44
45
46
47
48
49
50
51
52
from pymongo import *
import datetime
def insertUser(username, subreddits, client):
user = {
'username': username,
'subreddits' : subreddits,
'updated' : datetime.datetime.utcnow()
}
#client = MongoCient()
db = client.Reddit
collection = db.users
userID = collection.update({'username': user['username']}, {'username': user['username'], 'subreddits' : user['subreddits'], 'updated': user['updated']}, upsert=True)
return userID
def insertSub(sub, client):
sub = {
'name': sub,
'updated' : datetime.datetime.utcnow()
}
#client = MongoCient()
db = client.Reddit
collection = db.subreddits
userID = collection.update({'name': sub['name']}, {'name':sub['name'], 'updated': sub['updated']}, upsert=True)
return userID
def queryUser(username, client):
#client = MongoCient()
collection = client.Reddit.users
user = collection.find_one({'username': username})
return user
def update(username, subreddits, client):
#client = MongoCient()
collection = client.Reddit.users
collection.update({'username': username}, {"$set": {'subreddits': subreddits}})
def subreddits(client):
return client.Reddit.subreddits.find()
def allUsersInArray(userArray, client):
#client = MongoCient()
return client.Reddit.users.find({'username': {"$in": userArray}})
def tempUserList(client):
return client.Reddit.temp.find()
def allUsers(client):
return client.Reddit.users.find()
def tempBulkInsert(users, client):
return client.Reddit.temp.insert(users)