X-Git-Url: https://projects.mako.cc/source/twitter-api-cdsw-solutions/blobdiff_plain/1e2d406ccc7bfaa9c73ab809367ce5ae2ab6fc79:/twitter-stream2.py..d4653b5f599083dc7631ff1a215096ac58b626d8:/solution-geo-1.py diff --git a/twitter-stream2.py b/solution-geo-1.py similarity index 56% rename from twitter-stream2.py rename to solution-geo-1.py index 47855d8..3ba56d3 100644 --- a/twitter-stream2.py +++ b/solution-geo-1.py @@ -1,3 +1,10 @@ +# Alter the streaming code to include a "locations" filter. You need +# to use the order sw_lng, sw_lat, ne_lng, ne_lat for the four +# coordinates. + +# Note: to answer this, I used this website to find a good box: +# http://boundingbox.klokantech.com/ + import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET @@ -12,11 +19,12 @@ class StreamListener(tweepy.StreamListener): print(tweet.author.screen_name + "\t" + tweet.text) def on_error(self, status_code): - print( 'Error: ' + repr(status_code)) + print('Error: ' + repr(status_code)) return False l = StreamListener() streamer = tweepy.Stream(auth=auth, listener=l) -keywords = ['python', 'perl'] -streamer.filter(track = keywords) +# This should grab tweets within Seattle: +streamer.filter(locations=[-122.459696, 47.481002, -122.224433, 47.734136]) +