!pip install tweepy # Stolen from https://github.com/tweepy/tweepy/blob/master/examples/streaming.py from tweepy.streaming import StreamListener from tweepy import OAuthHandler from tweepy import Stream # NOTE: IT IS TERRIBLE PRACTICE TO ADD SECRET KEYS TO PUBLIC REPOS. # It makes sense for a test account in the context of this class, but almost nowhere else... don't do this. # Go to http://dev.twitter.com and create an app. # The consumer key and secret will be generated for you after consumer_key="6KoJEsgyFqvjpdstY4nC01mtA" consumer_secret="cNstALzQMaVumYH0fdxStJ1xdu4nfrxctxswFKiXuN4RdKFLeX" # After the step above, you will be redirected to your app's page. # Create an access token under the the "Your access token" section access_token="1482851370-VehH5dro4dlIzw2YUvQfXG3a0AifzwazcGvikna" access_token_secret="oeqwHeBE4IF6jlLpyRqNzIPYZWEMIFlvcdpiXLBIdltzg" class StdOutListener(StreamListener): """ A listener handles tweets are the received from the stream. This is a basic listener that just prints received tweets to stdout. """ def on_data(self, data): # You'll want to change this part to make things buffer print data return True def on_error(self, status): print status if __name__ == '__main__': l = StdOutListener() auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) stream = Stream(auth, l) stream.filter(track=['basketball'])