From: Josh Roesslein Date: Sat, 8 Aug 2009 18:45:03 +0000 (-0500) Subject: Added delete/limit message parsing. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=98589b5f1d416ef0002f3d33dce30828490f454b;p=tweepy.git Added delete/limit message parsing. --- diff --git a/stream_watcher.py b/stream_watcher.py index b31fd1f..7fbf89f 100644 --- a/stream_watcher.py +++ b/stream_watcher.py @@ -3,9 +3,13 @@ from getpass import getpass import tweepy -def callback(status): - - print status.text +def callback(t, stream_object): + if t == 'status': + print stream_object.text + elif t == 'delete': + print 'delete!!! id = %s' % stream_object['id'] + elif t == 'limit': + print 'limit!!! track=%s' % stream_object['track'] # Prompt for login credentials and setup stream object username = raw_input('Twitter username: ') diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 808c54a..fb52d8f 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -59,9 +59,7 @@ class Stream(object): if self.running is False: break conn.close() - print 'snoozing...' sleep(self.snooze_time) - print 'ok im awake!' except Exception: # any other exception is fatal, so kill loop break @@ -96,10 +94,11 @@ class Stream(object): # turn json data into status object if 'in_reply_to_status_id' in data: status = parse_status(data, self.api) - self.callback(status) - - # TODO: we should probably also parse delete/track messages - # and pass to a callback + self.callback('status', status) + elif 'delete' in data: + self.callback('delete', json.loads(data)['delete']['status']) + elif 'limit' in data: + self.callback('limit', json.loads(data)['limit']) def firehose(self, count=None, ): if self.running: