Added delete/limit message parsing.
authorJosh Roesslein <jroesslein@gmail.com>
Sat, 8 Aug 2009 18:45:03 +0000 (13:45 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Sat, 8 Aug 2009 18:45:03 +0000 (13:45 -0500)
stream_watcher.py
tweepy/streaming.py

index b31fd1fdccb0335b6afd2f4a4a188d1f713a828b..7fbf89f947c86cc2bdb731deadfc86ca067d3ad7 100644 (file)
@@ -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: ')
index 808c54a141848d99ffaf12ee14abadd114da067a..fb52d8fd948885ff1741aa209e1dd5cd078eaf16 100644 (file)
@@ -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: