Added STREAM_DELAY
authorGreenZapdos <green.zapdos@gmail.com>
Sun, 5 Oct 2014 05:40:58 +0000 (23:40 -0600)
committerGreenZapdos <green.zapdos@gmail.com>
Sun, 5 Oct 2014 05:40:58 +0000 (23:40 -0600)
rainbowstream/colorset/config
rainbowstream/rainbow.py

index 2d0b36e9ec3eb35608017b0f24a1c940ad4c062b..31e6294ad757bb49c691d5b7df7c331054547520 100644 (file)
@@ -45,6 +45,8 @@
     "IMAGE_SHIFT" : 2,
     // Image max height
     "IMAGE_MAX_HEIGHT" : 90,
+    // Seconds to wait before displaying another tweet, will drop all tweets while waiting.
+    "STREAM_DELAY" : 0,
     // Stream config
     "USER_DOMAIN" : "userstream.twitter.com",
     "PUBLIC_DOMAIN" : "stream.twitter.com",
index 06bdd5420f4a5c803148f41821b9fd10275bb384..ff654091bfb1187649025ad66aad7fd044c2a359 100644 (file)
@@ -1997,6 +1997,7 @@ def stream(domain, args, name='Rainbow Stream'):
         # Block new stream until other one exits
         StreamLock.acquire()
         g['stream_stop'] = False
+        last_tweet_time = time.time()
         for tweet in tweet_iter:
             if tweet is None:
                 printNicely("-- None --")
@@ -2017,32 +2018,34 @@ def stream(domain, args, name='Rainbow Stream'):
                 StreamLock.release()
                 break
             elif tweet.get('text'):
-                # Check the semaphore pause and lock (stream process only)
-                if g['pause']:
-                    continue
-                while c['lock']:
-                    time.sleep(0.5)
-                # Draw the tweet
-                draw(
-                    t=tweet,
-                    keyword=args.track_keywords,
-                    humanize=False,
-                    fil=args.filter,
-                    ig=args.ignore,
-                )
-                # Current readline buffer
-                current_buffer = readline.get_line_buffer().strip()
-                # There is an unexpected behaviour in MacOSX readline + Python 2:
-                # after completely delete a word after typing it,
-                # somehow readline buffer still contains
-                # the 1st character of that word
-                if current_buffer and g['cmd'] != current_buffer:
-                    sys.stdout.write(
-                        g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
-                    sys.stdout.flush()
-                elif not c['HIDE_PROMPT']:
-                    sys.stdout.write(g['decorated_name'](c['PREFIX']))
-                    sys.stdout.flush()
+                if time.time() - last_tweet_time >= get_config("STREAM_DELAY"):
+                  last_tweet_time = time.time()
+                  # Check the semaphore pause and lock (stream process only)
+                  if g['pause']:
+                      continue
+                  while c['lock']:
+                      time.sleep(0.5)
+                  # Draw the tweet
+                  draw(
+                      t=tweet,
+                      keyword=args.track_keywords,
+                      humanize=False,
+                      fil=args.filter,
+                      ig=args.ignore,
+                  )
+                  # Current readline buffer
+                  current_buffer = readline.get_line_buffer().strip()
+                  # There is an unexpected behaviour in MacOSX readline + Python 2:
+                  # after completely delete a word after typing it,
+                  # somehow readline buffer still contains
+                  # the 1st character of that word
+                  if current_buffer and g['cmd'] != current_buffer:
+                      sys.stdout.write(
+                          g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
+                      sys.stdout.flush()
+                  elif not c['HIDE_PROMPT']:
+                      sys.stdout.write(g['decorated_name'](c['PREFIX']))
+                      sys.stdout.flush()
             elif tweet.get('direct_message'):
                 # Check the semaphore pause and lock (stream process only)
                 if g['pause']: