forked from comsysto/twitter-realtime-heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtstream.py
47 lines (34 loc) · 1.02 KB
/
tstream.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
import tweepy
import json
from pymongo import Connection
from bson import json_util
from tweepy.utils import import_simplejson
json = import_simplejson()
mongocon = Connection()
db = mongocon.tstream
col = db.tweets_tail
consumer_key = ''
consumer_secret = ''
access_token_key = ''
access_token_secret = ''
auth1 = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth1.set_access_token(access_token_key, access_token_secret)
class StreamListener(tweepy.StreamListener):
mongocon = Connection()
db = mongocon.tstream
col = db.tweets
json = import_simplejson()
def on_status(self, tweet):
print 'Ran on_status'
def on_error(self, status_code):
return False
def on_data(self, data):
if data[0].isdigit():
pass
else:
col.insert(json.loads(data))
print(json.loads(data))
l = StreamListener()
streamer = tweepy.Stream(auth=auth1, listener=l)
setTerms = ['bigdata', 'devops', 'hadoop', 'twitter']
streamer.filter(track = setTerms)