X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=rainbowstream%2Frainbow.py;h=377f7d6ed2a1968112f92000967b21d9b78255d8;hb=879a94483411a5658befb3cec62a9b22adfece56;hp=ff654091bfb1187649025ad66aad7fd044c2a359;hpb=7f57719b119584ddcf7a56101d271c6b7a54f42b;p=rainbowstream.git diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index ff65409..377f7d6 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 @@ -198,9 +204,8 @@ def init(args): name = credential['name'] if not get_config('PREFIX'): set_config('PREFIX', screen_name) - c['PREFIX'] = emojize(c['PREFIX']) - g['PREFIX'] = u2str(c['PREFIX']) c['original_name'] = g['original_name'] = screen_name[1:] + g['PREFIX'] = u2str(emojize(format_prefix())) g['full_name'] = name g['decorated_name'] = lambda x: color_func( c['DECORATED_NAME'])('[' + x + ']: ', rl=True) @@ -1238,7 +1243,7 @@ def switch(): g['stream_stop'] = True args.track_keywords = keyword # Reset prefix - g['PREFIX'] = u2str(emojize(c['PREFIX'])) + g['PREFIX'] = u2str(emojize(format_prefix(keyword = keyword))) # Start new thread th = threading.Thread( target=stream, @@ -1252,7 +1257,7 @@ def switch(): # Kill old thread g['stream_stop'] = True # Reset prefix - g['PREFIX'] = u2str(emojize(c['PREFIX'])) + g['PREFIX'] = u2str(emojize(format_prefix())) # Start new thread th = threading.Thread( target=stream, @@ -1266,7 +1271,8 @@ def switch(): elif target == 'list': owner, slug = get_slug() # Force python 2 not redraw readline buffer - g['PREFIX'] = g['cmd'] = '/'.join([owner, slug]) + listname = '/'.join([owner, slug]) + g['PREFIX'] = g['cmd'] = u2str(emojize(format_prefix(listname = listname))) printNicely(light_yellow('getting list members ...')) # Get members t = Twitter(auth=authen()) @@ -1403,7 +1409,7 @@ def config(): g['decorated_name'] = lambda x: color_func( c['DECORATED_NAME'])('[' + x + ']: ') elif key == 'PREFIX': - g['PREFIX'] = u2str(emojize(c['PREFIX'])) + g['PREFIX'] = u2str(emojize(format_prefix())) reload_config() printNicely(green('Updated successfully.')) except: @@ -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 ] )) @@ -1954,7 +1964,7 @@ def reconn_notice(): light_green("h stream") + \ light_magenta(" for more details.") printNicely(guide) - sys.stdout.write(g['decorated_name'](c['PREFIX'])) + sys.stdout.write(g['decorated_name'](g['PREFIX'])) sys.stdout.flush() @@ -2018,34 +2028,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'](g['PREFIX']) + current_buffer) + sys.stdout.flush() + elif not c['HIDE_PROMPT']: + sys.stdout.write(g['decorated_name'](g['PREFIX'])) + sys.stdout.flush() elif tweet.get('direct_message'): # Check the semaphore pause and lock (stream process only) if g['pause']: @@ -2056,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'](g['PREFIX'])) + sys.stdout.flush() def fly(): @@ -2072,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