formatting fix for code
[twitter-api-cdsw-solutions] / solution-geo-1.py
1 # Alter the streaming code to include a "locations" filter. You need
2 # to use the order sw_lng, sw_lat, ne_lng, ne_lat for the four
3 # coordinates.
4
5 # Note: to answer this, I used this website to find a good box:
6 # http://boundingbox.klokantech.com/
7
8 import encoding_fix
9 import tweepy
10 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
11
12 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
13 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
14
15 api = tweepy.API(auth)
16
17 class StreamListener(tweepy.StreamListener):
18     def on_status(self, tweet):
19         print(tweet.author.screen_name + "\t" + tweet.text)
20
21     def on_error(self, status_code):
22         print('Error: ' + repr(status_code))
23         return False
24
25 l = StreamListener()
26 streamer = tweepy.Stream(auth=auth, listener=l)
27
28 # This should grab tweets within Seattle:
29 streamer.filter(locations=[-122.459696, 47.481002, -122.224433, 47.734136])
30

Benjamin Mako Hill || Want to submit a patch?