-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetoo.py
executable file
·33 lines (26 loc) · 865 Bytes
/
metoo.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
"""Twitter Analysis."""
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
ACCESS_TOKEN = "access-token"
ACCESS_TOKEN_SECRET = "access-secret"
API_KEY = "api-key"
API_SECRET = "api-secret"
class StdOutListener(StreamListener):
"""This is a basic listener that just prints received tweets to stdout."""
def on_data(self, data):
"""On data."""
print data
return True
def on_error(self, status):
"""On error."""
print status
listener = StdOutListener()
auth = OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
stream = Stream(auth, listener)
try:
stream.filter(track=['metoo'], async=True, stall_warnings=True)
except:
print "Restarting..."
stream.filter(track=['metoo'], async=True, stall_warnings=True)