-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheater.py
38 lines (28 loc) · 1.1 KB
/
eater.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
from tweater import TwEater, TwOrder
from datetime import datetime
import json
# Write tweets batch to a file in folder dir
def digest_2_file(tweets, dir):
t = datetime.now()
fn = dir + '/' + str(t.microsecond + (t.second + t.day * 86400) * 10**6) + '.json'
print ' ------ Saved to file: ' + fn + ' ------'
with open(fn, 'w') as f:
json.dump(tweets, f)
# Write file to MongoDB collection
def digest_2_mongo(tweets, col):
print ' ------ Save to MongoDB ------'
col.insert_many(tweets)
if __name__ == "__main__":
print "\n " + unicode(datetime.now())
# Initialize the parameters
TwOrder.order('order.conf')
# to.TwOrder.order(user='BarackObama')
# Write tweets to json file
TwEater.eatTweets(digest_2_file, 'test')
# Collect replies of specific tweet_id of a user, username is case-sensitive
# print tc.TwChef.shopComments('BarackObama', '876456804305252353')
# Write tweets to Mongo Collection
# client = MongoClient()
# te.TwEater.eatTweets(digest_2_mongo, client.test.tweets)
print " " + unicode(datetime.now())
print " Done!"