Last active
December 20, 2015 17:59
-
-
Save dbonadiman/6172952 to your computer and use it in GitHub Desktop.
Revisions
-
dbonadiman revised this gist
Mar 29, 2014 . 1 changed file with 18 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,7 @@ import json import tweepy class StdOutListener(tweepy.StreamListener): def do_stuff(self, pdata): print pdata['text'] @@ -17,25 +12,29 @@ def on_data(self, data): pdata = json.loads(data) self.do_stuff(pdata) return True except Exception: return True def on_error(self, status): print "Stream on_error: ", status def connect(): # Authenticate auth = tweepy.OAuthHandler('Consumer key', 'Consumer secret') auth.set_access_token('Access token', 'Access token secret') return auth def stream(): try: # Read stream stream = tweepy.Stream(connect(), StdOutListener()) #stream.filter(track=['word']) stream.sample() except Exception: print 'could not connect to Twitter' if __name__ == '__main__': stream() -
dbonadiman created this gist
Aug 7, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ import os import sys import json import tweepy ######## # Tweepy data listener ######## class StdOutListener(tweepy.StreamListener): def do_stuff(self, pdata): print pdata['text'] def on_data(self, data): pdata = "" try: pdata = json.loads(data) self.do_stuff(pdata) return True except Exception as e: return True def on_error(self, status): print "Stream on_error: ", status ####### # Init ####### if __name__ == '__main__': try: # Authenticate auth = tweepy.OAuthHandler('Consumer key','Consumer secret') auth.set_access_token('Access token','Access token secret') # Read stream stream = tweepy.Stream(auth, StdOutListener()) #stream.filter(track=['word']) stream.sample() except Exception as e: print 'could not connect to Twitter'