from getpass import getpass
from textwrap import TextWrapper
import tweepy
import time
class StreamWatcherListener(tweepy.StreamListener):
status_wrapper = TextWrapper(width=60, initial_indent=' ', subsequent_indent=' ')
def on_status(self, status):
try:
print self.status_wrapper.fill(status.text)
print '\n %s %s via %s\n' % (status.author.screen_name, status.created_at, status.source)
except:
# Catch any unicode errors while printing to console
# and just ignore them to avoid breaking application.
pass
def on_error(self, status_code):
print 'An error has occured! Status code = %s' % status_code
return True # keep stream alive
def on_timeout(self):
print 'Snoozing Zzzzzz'
username="abc"
password="abc"
auth = tweepy.BasicAuthHandler(username, password)
listener = StreamWatcherListener()
stream=tweepy.Stream(auth,listener)
stream.filter(locations=[-122.75,36.8,-121.75,37.8,-74,40,-73,41])
This just prints to console. But what if I want to do more with it? The library I'm using is here.