-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo_connect.py
57 lines (38 loc) · 1.39 KB
/
mongo_connect.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pymongo
import json
import config
# takes a list of json objects and inserts it into mthe MLab MongoDB
def put_db(texts):
connection = pymongo.MongoClient(config.DB_HOST, config.DB_PORT)
db = connection[config.DB_NAME]
db.authenticate(config.DB_USER, config.DB_PASS)
for text in texts:
db.docs.insert(text)
def getCollection():
connection = pymongo.MongoClient(config.DB_HOST, config.DB_PORT)
db = connection[config.DB_NAME]
db.authenticate(config.DB_USER, config.DB_PASS)
return db.docs
def getData():
connection = pymongo.MongoClient(config.DB_HOST, config.DB_PORT)
db = connection[config.DB_NAME]
db.authenticate(config.DB_USER, config.DB_PASS)
return db.docs.find()
def getTrueNews(num):
connection = pymongo.MongoClient(config.DB_HOST, config.DB_PORT)
db = connection[config.DB_NAME]
db.authenticate(config.DB_USER, config.DB_PASS)
return db.docs.find({'truth': True}).limit(num)
def getFakeNews(num):
connection = pymongo.MongoClient(config.DB_HOST, config.DB_PORT)
db = connection[config.DB_NAME]
db.authenticate(config.DB_USER, config.DB_PASS)
return db.docs.find({'truth': False}).limit(num)
def doesExist(title):
connection = pymongo.MongoClient(config.DB_HOST, config.DB_PORT)
db = connection[config.DB_NAME]
db.authenticate(config.DB_USER, config.DB_PASS)
if db.docs.find({'title': title}).count() > 0:
return True
else:
return False