How can I stream tweets using the Python language?
You have several options to interact with the Streaming APIs from Python, for instance using one of the libraries listed at [node:126].
Tweepy is one of them, and here is an example code to use [node:10389]:
Perfect !
Here’s an example using my TwitterAPI library (https://github.com/geduldig/TwitterAPI)
from TwitterAPI import TwitterAPI CONSUMER_KEY = '' CONSUMER_SECRET = '' ACCESS_TOKEN_KEY = '' ACCESS_TOKEN_SECRET = ‘’ api = TwitterAPI( CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET) r = api.request(‘statuses/filter’, {‘track’: ‘pizza’}) for item in r: print(item[‘text’] if ‘text’ in item else item)
CONSUMER_KEY = '' CONSUMER_SECRET = '' ACCESS_TOKEN_KEY = '' ACCESS_TOKEN_SECRET = ‘’
api = TwitterAPI( CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
r = api.request(‘statuses/filter’, {‘track’: ‘pizza’})
for item in r: print(item[‘text’] if ‘text’ in item else item)