Created
February 2, 2017 15:31
-
-
Save naranjja/b0af0fb4d6457e8589b45266cf169e4c to your computer and use it in GitHub Desktop.
Tweepy Twitter stream
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 characters
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