X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=rainbowstream%2Frainbow.py;h=765ce389d6eb03ff7841ffa5e0436d8e4551e32e;hb=eb9b6273dc3f382b20ee055dc7ed4d3116532874;hp=d67be609a9378dd515025c7e06e3c5163768ee94;hpb=9ee4a3cc95dcf0a00193655e5b543a36ce835198;p=rainbowstream.git diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index d67be60..765ce38 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -482,6 +482,28 @@ def unfavorite(): printNicely('') +def share(): + """ + Copy url of a tweet to clipboard + """ + t = Twitter(auth=authen()) + try: + id = int(g['stuff'].split()[0]) + except: + printNicely(red('Sorry I can\'t understand.')) + return + tid = c['tweet_dict'][id] + tweet = t.statuses.show(id=tid) + url = 'https://twitter.com/' + \ + tweet['user']['screen_name'] + '/status/' + str(tid) + import platform + if platform.system().lower() == 'darwin': + os.system("echo '%s' | pbcopy" % url) + printNicely(green('Copied tweet\'s url to clipboard.')) + else: + printNicely('Direct link: ' + yellow(url)) + + def delete(): """ Delete @@ -1394,6 +1416,9 @@ def help_tweets(): usage += s * 2 + \ light_green('ufav 12 ') + ' will unfavorite tweet with ' + \ light_yellow('[id=12]') + '.\n' + usage += s * 2 + \ + light_green('share 12 ') + ' will copy the url of the tweet with ' + \ + light_yellow('[id=12]') + ' to your clipboard.\n' usage += s * 2 + \ light_green('del 12 ') + ' will delete tweet with ' + \ light_yellow('[id=12]') + '.\n' @@ -1674,6 +1699,7 @@ cmdset = [ 'rep', 'del', 'ufav', + 'share', 's', 'mes', 'show', @@ -1719,6 +1745,7 @@ funcset = [ reply, delete, unfavorite, + share, search, message, show, @@ -1777,6 +1804,7 @@ def listen(): [], # reply [], # delete [], # unfavorite + [], # url ['#'], # search ['@'], # message ['image'], # show image @@ -1862,6 +1890,21 @@ def listen(): printNicely(red('OMG something is wrong with Twitter right now.')) +def reconn_notice(): + """ + Notice when Hangup or Timeout + """ + guide = light_magenta("You can use ") + \ + light_green("switch") + \ + light_magenta(" command to return to your stream.\n") + guide += light_magenta("Type ") + \ + light_green("h stream") + \ + light_magenta(" for more details.") + printNicely(guide) + sys.stdout.write(g['decorated_name'](c['PREFIX'])) + sys.stdout.flush() + + def stream(domain, args, name='Rainbow Stream'): """ Track the stream @@ -1905,24 +1948,21 @@ def stream(domain, args, name='Rainbow Stream'): if tweet is None: printNicely("-- None --") elif tweet is Timeout: + # Because the stream check for each 0.3s + # so we shouldn't output anything here if(g['stream_stop']): StreamLock.release() break elif tweet is HeartbeatTimeout: printNicely("-- Heartbeat Timeout --") - guide = light_magenta("You can use ") + \ - light_green("switch") + \ - light_magenta(" command to return to your stream.\n") - guide += light_magenta("Type ") + \ - light_green("h stream") + \ - light_magenta(" for more details.") - printNicely(guide) - sys.stdout.write(g['decorated_name'](c['PREFIX'])) - sys.stdout.flush() + reconn_notice() StreamLock.release() break elif tweet is Hangup: printNicely("-- Hangup --") + reconn_notice() + StreamLock.release() + break elif tweet.get('text'): # Check the semaphore pause and lock (stream process only) if g['pause']: