X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Frainbow.py;h=08cdcb7409cac73a65a3c2486fa138af92ce6678;hp=f58d59c314dc158b3694394dd592054f949c7af3;hb=38a6dc308c60aa43ad84f9ff0b9230540518ec28;hpb=571ea706e5688d01bd83bafbbe601a0d94ac90ab diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index f58d59c..08cdcb7 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -122,6 +122,7 @@ def init(args): name = credential['name'] if not get_config('PREFIX'): set_config('PREFIX', screen_name) + g['PREFIX'] = u2str(c['PREFIX']) c['original_name'] = g['original_name'] = screen_name[1:] g['full_name'] = name g['decorated_name'] = lambda x: color_func( @@ -132,8 +133,12 @@ def init(args): g['themes'] = themes g['pause'] = False g['message_threads'] = {} + # Events + g['events'] = [] # Startup cmd g['cmd'] = '' + # Retweet of mine events + c['events'] = [] # Semaphore init c['lock'] = False # Init tweet dict and message dict @@ -195,6 +200,19 @@ def home(): printNicely('') +def notification(): + """ + Show notifications + """ + g['events'] = g['events'] + c['events'] + if g['events']: + for e in g['events']: + print_event(e) + printNicely('') + else: + printNicely(magenta('Nothing at this time.')) + + def mentions(): """ Mentions timeline @@ -249,13 +267,24 @@ def search(): Search """ t = Twitter(auth=authen()) - g['stuff'] = g['stuff'].strip() - rel = t.search.tweets(q=g['stuff'])['statuses'] + # Setup query + query = g['stuff'].strip() + type = c['SEARCH_TYPE'] + if type not in ['mixed', 'recent', 'popular']: + type = 'mixed' + max_record = c['SEARCH_MAX_RECORD'] + count = min(max_record, 100) + # Perform search + rel = t.search.tweets( + q=query, + type=type, + count=count + )['statuses'] + # Return results if rel: printNicely('Newest tweets:') - for i in reversed(xrange(c['SEARCH_MAX_RECORD'])): - draw(t=rel[i], - keyword=g['stuff']) + for i in reversed(xrange(count)): + draw(t=rel[i], keyword=query) printNicely('') else: printNicely(magenta('I\'m afraid there is no result')) @@ -1214,6 +1243,8 @@ def help_discover(): light_green('trend JP Tokyo') + '.\n' usage += s * 2 + light_green('home') + ' will show your timeline. ' + \ light_green('home 7') + ' will show 7 tweets.\n' + usage += s * 2 + \ + light_green('notification') + ' will show your recent notification.\n' usage += s * 2 + light_green('mentions') + ' will show mentions timeline. ' + \ light_green('mentions 7') + ' will show 7 mention tweets.\n' usage += s * 2 + light_green('whois @mdo') + ' will show profile of ' + \ @@ -1523,6 +1554,7 @@ cmdset = [ 'switch', 'trend', 'home', + 'notification', 'view', 'mentions', 't', @@ -1567,6 +1599,7 @@ funcset = [ switch, trend, home, + notification, view, mentions, tweet, @@ -1624,6 +1657,7 @@ def listen(): ['public', 'mine'], # switch [], # trend [], # home + [], # notification ['@'], # view [], # mentions [], # tweet @@ -1689,7 +1723,7 @@ def listen(): try: # raw_input if g['prefix']: - line = raw_input(g['decorated_name'](c['PREFIX'])) + line = raw_input(g['decorated_name'](g['PREFIX'])) else: line = raw_input() # Save cmd to compare with readline buffer @@ -1773,7 +1807,7 @@ def stream(domain, args, name='Rainbow Stream'): 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() StreamLock.release() break @@ -1801,10 +1835,10 @@ def stream(domain, args, name='Rainbow Stream'): # 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)) + g['decorated_name'](g['PREFIX']) + str2u(current_buffer)) sys.stdout.flush() elif not c['HIDE_PROMPT']: - sys.stdout.write(g['decorated_name'](c['PREFIX'])) + 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) @@ -1813,6 +1847,9 @@ def stream(domain, args, name='Rainbow Stream'): while c['lock']: time.sleep(0.5) print_message(tweet['direct_message']) + elif tweet.get('event'): + g['events'].append(tweet) + print_event(tweet) except TwitterHTTPError: printNicely('') printNicely(