forked from swanson/duel-of-tweets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firehose.py
executable file
·39 lines (32 loc) · 1.03 KB
/
firehose.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
#!/usr/bin/env python
from mongoengine import *
import tweetstream
from datetime import datetime
from db.document import StoredTweet
import sys
import json
import logging
if __name__ == "__main__":
# start up the default logging
logging.basicConfig(level=logging.DEBUG)
# get the config
try:
with open('config.json') as cfg:
config = json.load(cfg)
except:
logging.critical('couldnt open config!')
sys.exit(-1)
# connect to mongodb
try:
connect('tweet-store')
except:
logging.critical('couldnt connect to mongodb!')
sys.exit(-1)
else:
logging.info('connected to mongodb')
words = [config['user_frontend'], config['user_bot']]
stream = tweetstream.TrackStream(config['user_frontend'], config['password_frontend'], words)
for tweet in stream:
logging.debug("Storing tweet %s" % tweet['text'])
ts = StoredTweet(body = tweet['text'], user = tweet['user']['screen_name'], timestamp = datetime.now())
ts.save()