Created
July 29, 2011 01:06
-
-
Save mtrovo/1112928 to your computer and use it in GitHub Desktop.
Twitter Streaming API sample using the filter 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
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
from tweepy.streaming import StreamListener, Stream | |
from tweepy.auth import BasicAuthHandler | |
from tweepy.api import API | |
import tweepy | |
class MyStreamListener(StreamListener): | |
def __init__(self, api=None): | |
StreamListener.__init__(self, api=api) | |
def on_status(self, status): | |
print "@%s: %s" % (status.user.screen_name, status.text) | |
def on_error(self, status_code): | |
print "ERROR: ",status_code | |
def on_limit(self, track): | |
print "LIMIT: ", track | |
def on_timeout(self): | |
print "TIMEOUT!" | |
def filter_track(): | |
track=["python"] | |
stream_auth = BasicAuthHandler('<USERNAME>', '<PASSWORD>') | |
api = API() | |
stream = Stream(stream_auth, MyStreamListener(api)) | |
print 'start filter track ', ','.join(track) | |
stream.filter(track=track) | |
if __name__ == "__main__": | |
filter_track() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bstrathearn i saw this too, actually when I created this gist they already had this warning. I hope they don't deprecate it so soon, the last time I checked tweepy it still didn't support Streaming API login with OAuth.