-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_from_db.py
More file actions
35 lines (29 loc) · 797 Bytes
/
read_from_db.py
File metadata and controls
35 lines (29 loc) · 797 Bytes
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
from mongo_auth import *
import pymongo
import json
from pymongo import MongoClient
from bson.json_util import dumps
import unicodedata
import string
import sys
reload(sys)
sys.setdefaultencoding('utf8')
if __name__ == '__main__':
client = MongoClient('mongodb://' + MONGO_USERNAME + ':' + MONGO_PASSWORD
+ '@watcharaphat.com/twitter_db')
db = client['twitter_db']
if(len(sys.argv) < 2):
print "usage: python read_from_db [collection_name]"
sys.exit()
collection = db[sys.argv[1]]
cursor = collection.find(
{},
{"text": 1, "_id": 0}
)
i = 0
for document in cursor:
if (i < 10000):
print dumps(document, ensure_ascii=False)
i = i + 1
else:
sys.exit()