script/stream/recorder_tweetstream.py
changeset 207 621fa6caec0c
parent 206 6d642d650470
child 242 cdd7d3c0549c
--- a/script/stream/recorder_tweetstream.py	Fri Jul 01 10:06:36 2011 +0200
+++ b/script/stream/recorder_tweetstream.py	Fri Jul 01 18:59:13 2011 +0200
@@ -10,7 +10,7 @@
 import sys
 import time
 import tweetstream
-import tweetstream.auth
+import tweepy.auth
 socket._fileobject.default_bufsize = 0
 
 
@@ -22,7 +22,7 @@
 #just put it in a sqlite3 tqble
 
 
-class ReconnectingTweetStream(tweetstream.TrackStream):
+class ReconnectingTweetStream(tweetstream.FilterStream):
     """TweetStream class that automatically tries to reconnect if the
     connecting goes down. Reconnecting, and waiting for reconnecting, is
     blocking.
@@ -44,12 +44,12 @@
 
     """
 
-    def __init__(self, auth, keywords, url="track", reconnects=3, error_cb=None, retry_wait=5, **kwargs):
+    def __init__(self, auth, keywords, reconnects=3, error_cb=None, retry_wait=5, **kwargs):
         self.max_reconnects = reconnects
         self.retry_wait = retry_wait
         self._reconnects = 0
         self._error_cb = error_cb
-        super(ReconnectingTweetStream, self).__init__(auth, keywords, url, **kwargs)
+        super(ReconnectingTweetStream, self).__init__(auth=auth, track=keywords, **kwargs)
 
     def next(self):
         while True:
@@ -90,11 +90,11 @@
     track_list = [k for k in track_list.split(',')]
     
     if username and password:
-        auth = tweetstream.auth.BasicAuthHandler(username, password)        
+        auth = tweepy.auth.BasicAuthHandler(username, password)        
     else:
         consumer_key = models.CONSUMER_KEY
         consumer_secret = models.CONSUMER_SECRET
-        auth = tweetstream.auth.OAuthHandler(consumer_key, consumer_secret, secure=False)
+        auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret, secure=False)
         auth.set_access_token(*(utils.get_oauth_token(token_filename)))
     
     if duration >= 0:
@@ -107,7 +107,7 @@
                 print "Stop recording after %d seconds." % (duration)
                 break
             process_tweet(tweet, session, debug, token_filename)
-            logging.info("Tweet count: %d - current rate : %d - running : %s"%(stream.count, stream.rate, int(time.time()-stream.starttime)))
+            logging.info("Tweet count: %d - current rate : %.2f - running : %s"%(stream.count, stream.rate, int(time.time()-stream.starttime)))
             session.commit()
     finally:
         stream.close()