Streaming with python


#1

How can I stream tweets using the Python language?


#2

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]:


#3

Perfect !


#4

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)