X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Frainbow.py;h=f06b510aa708d39896a8fa0ef1f07ba9b7b15514;hp=06bdd5420f4a5c803148f41821b9fd10275bb384;hb=620587157c57f179960c2576b591819056f813bb;hpb=a65129d47a38d80460bf19aa6003015f7606dde7 diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 06bdd54..f06b510 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -27,6 +27,7 @@ from .interactive import * from .c_image import * from .py3patch import * from .emoji import * +from .util import * # Global values g = {} @@ -178,6 +179,11 @@ def upgrade_center(): notice += light_magenta('You should upgrade with ') notice += light_green('pip install -U rainbowstream') printNicely(notice) + else: + notice = light_yellow('You are running latest version (') + notice += light_green(current) + notice += light_yellow(')') + printNicely(notice) except: pass @@ -1660,6 +1666,7 @@ def help(): usage += s * 2 + light_green('p') + ' will pause the stream.\n' usage += s * 2 + light_green('r') + ' will unpause the stream.\n' usage += s * 2 + light_green('c') + ' will clear the screen.\n' + usage += s * 2 + light_green('v') + ' will show version info.\n' usage += s * 2 + light_green('q') + ' will quit.\n' # End usage += '\n' @@ -1778,7 +1785,8 @@ cmdset = [ 'p', 'r', 'c', - 'q' + 'v', + 'q', ] # Handle function set @@ -1824,7 +1832,8 @@ funcset = [ pause, replay, clear, - quit + upgrade_center, + quit, ] @@ -1902,6 +1911,7 @@ def listen(): [], # pause [], # reconnect [], # clear + [], # version [], # quit ] )) @@ -1997,6 +2007,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,6 +2028,10 @@ def stream(domain, args, name='Rainbow Stream'): StreamLock.release() break elif tweet.get('text'): + # 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 @@ -2053,10 +2068,13 @@ def stream(domain, args, name='Rainbow Stream'): elif tweet.get('event'): c['events'].append(tweet) print_event(tweet) - except TwitterHTTPError: + except TwitterHTTPError as e: printNicely('') printNicely( - magenta("We have maximum connection problem with twitter'stream API right now :(")) + magenta("We have connection problem with twitter'stream API right now :(")) + detail_twitter_error(e) + sys.stdout.write(g['decorated_name'](c['PREFIX'])) + sys.stdout.flush() def fly(): @@ -2069,11 +2087,11 @@ def fly(): proxy_connect(args) init(args) # Twitter API connection problem - except TwitterHTTPError: + except TwitterHTTPError as e: printNicely('') printNicely( - magenta("We have connection problem with twitter'stream API right now :(")) - printNicely(magenta("Let's try again later.")) + magenta("We have connection problem with twitter'REST API right now :(")) + detail_twitter_error(e) save_history() sys.exit() # Proxy connection problem