Skip to content

Instantly share code, notes, and snippets.

@naranjja
Created February 2, 2017 15:31
Show Gist options
  • Save naranjja/b0af0fb4d6457e8589b45266cf169e4c to your computer and use it in GitHub Desktop.
Save naranjja/b0af0fb4d6457e8589b45266cf169e4c to your computer and use it in GitHub Desktop.
Tweepy Twitter stream
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
class StdOutListener(StreamListener):
def on_data(self, data):
# data in the form of JSON
return True
def on_error(self, status):
# you can implement handlers for different status codes
raise
listener = StdOutListener()
authentication = OAuthHandler(consumer_key, consumer_secret)
authentication.set_access_token(access_token, access_token_secret)
stream = Stream(authentication, listener)
stream.filter(track=['term1','term2','term3'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment