-
Notifications
You must be signed in to change notification settings - Fork 4
/
streaming.py
36 lines (28 loc) · 990 Bytes
/
streaming.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
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from save_to_db import save_to_db
# Authentication details.
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
# This is the listener, resposible for receiving data
class StdOutListener(StreamListener):
def on_status(self, status):
tweet_url = "http://twitter.com/" + status.user.screen_name + "/status/" + status.id_str
print "TWEET", status.text
print "URL", tweet_url
save_to_db(status.user.screen_name, status.text, tweet_url, status.id_str)
def on_error(self, status):
print status
if __name__ == "__main__":
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
ids = []
with open("ids.csv") as f:
for row in f:
ids.append(row)
stream = Stream(auth, l)
stream.filter(ids)