made a collection of twitter api solutions
[twitter-api-cdsw-solutions] / solution-geo-2.py
diff --git a/solution-geo-2.py b/solution-geo-2.py
new file mode 100644 (file)
index 0000000..c7830ff
--- /dev/null
@@ -0,0 +1,28 @@
+# What are people tweeting about in Times Square today?
+
+# 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
+
+auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
+auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
+
+api = tweepy.API(auth)
+
+class StreamListener(tweepy.StreamListener):
+    def on_status(self, tweet):
+        print(tweet.author.screen_name + "\t" + tweet.text)
+
+    def on_error(self, status_code):
+        print('Error: ' + repr(status_code))
+        return False
+
+l = StreamListener()
+streamer = tweepy.Stream(auth=auth, listener=l)
+
+# This should grab tweets in Times Square
+streamer.filter(locations=[-73.9864799803,40.7575460197,-73.9837820197,40.7602439803])
+

Benjamin Mako Hill || Want to submit a patch?