forked from sjwarner/RoyalHackaway2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet_listener.py
43 lines (35 loc) · 1.21 KB
/
tweet_listener.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
from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
#consumer key, consumer secret, access token, access secret.
consumer_key = #secret_here
consumer_secret = #secret_here
access_token = #secret_here
access_secret = #secret_here
# Note these are some invalid test users.
users=["1234567890"]
# hash_tags=["#hashtag"]
# terms=["keyword1","keyword2","keyword3","keyword4"]
class StdOutListener(StreamListener):
""" A listener handles tweets that are received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
jsonData = json.loads(data)
text = jsonData['text']
place = jsonData['place']
place_name = place['full_name']
print(text)
print(place_name)
return True
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_secret)
stream = Stream(auth, l)
# stream.filter(track=hash_tags)
stream.filter(follow=users)