Add STREAM_DELAY config key
authorOrakaro <nhatminh_179@hotmail.com>
Sun, 5 Oct 2014 07:24:46 +0000 (16:24 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Sun, 5 Oct 2014 07:24:46 +0000 (16:24 +0900)
docs/conf.py
docs/index.rst
rainbowstream/rainbow.py
setup.py

index dee298a..a00eaa8 100644 (file)
@@ -48,9 +48,9 @@ copyright = u'2014, Vu Nhat Minh'
 # built documents.
 #
 # The short X.Y version.
-version = '1.1.5'
+version = '1.1.6'
 # The full version, including alpha/beta/rc tags.
-release = '1.1.5'
+release = '1.1.6'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
index cb7da71..865af09 100644 (file)
@@ -359,6 +359,8 @@ You also can view or set a new value of every config key by ``config`` command (
 \r
 -  ``IMAGE_MAX_HEIGHT``: max height of image in '-iot'/'--image-on-term' mode.\r
 \r
+-  ``STREAM_DELAY``: seconds to wait before displaying another tweet, will drop all tweets while waiting. This value can be used to slow down the stream.\r
+\r
 -  ``USER_DOMAIN``: user URL of Twitter Streaming API.\r
 \r
 -  ``PUBLIC_DOMAIN``: public URL of Twitter Streaming API.\r
index ff65409..2b8a456 100644 (file)
@@ -2018,34 +2018,36 @@ def stream(domain, args, name='Rainbow Stream'):
                 StreamLock.release()
                 break
             elif tweet.get('text'):
-                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()
+                # Slow down the stream by STREAM_DELAY config key
+                if time.time() - last_tweet_time < c['STREAM_DELAY']:
+                    continue
+                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']:
index c86e68c..121ce52 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ import os
 import os.path
 
 # Bumped version
-version = '1.1.5'
+version = '1.1.6'
 
 # Require
 install_requires = [