From 413857b50f9953f73a5e552091b9d2b90d2f5a90 Mon Sep 17 00:00:00 2001 From: Orakaro Date: Thu, 25 Sep 2014 02:24:24 +0900 Subject: [PATCH] add share command and show Twitter client name --- docs/conf.py | 4 ++-- docs/index.rst | 2 ++ rainbowstream/colorset/config | 2 +- rainbowstream/colorset/larapaste.json | 1 + rainbowstream/colorset/monokai.json | 1 + rainbowstream/colorset/solarized.json | 1 + rainbowstream/colorset/tomorrow_night.json | 1 + rainbowstream/draw.py | 12 +++++++++++ rainbowstream/rainbow.py | 24 ++++++++++++++++++++++ setup.py | 2 +- theme.md | 6 +++++- 11 files changed, 51 insertions(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index eafb44f..c0cbe38 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -48,9 +48,9 @@ copyright = u'2014, Vu Nhat Minh' # built documents. # # The short X.Y version. -version = '1.0.7' +version = '1.0.8' # The full version, including alpha/beta/rc tags. -release = '1.0.7' +release = '1.0.8' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index e42c927..f241303 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -144,6 +144,8 @@ Here is full list of supported command: - ``ufav 12`` will unfavorite tweet with *[id=12]*. +- ``share 12`` will copy tweet with *[id=12]* to your clipboard. + - ``del 12`` will delete tweet with *[id=12]*. - ``show image 12`` will show the image in tweet with *[id=12]* in your OS’s image viewer. diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index 14046fe..2d0b36e 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -53,7 +53,7 @@ "FORMAT": { "TWEET": { "CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S", - "DISPLAY" : "\n #name #nick #clock \n \u20AA:#rt_count \u2665:#fa_count id:#id #fav\n #tweet" + "DISPLAY" : "\n #name #nick #clock \n \u20AA:#rt_count \u2665:#fa_count id:#id via #client #fav\n #tweet" }, "MESSAGE": { "CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S", diff --git a/rainbowstream/colorset/larapaste.json b/rainbowstream/colorset/larapaste.json index fd75cc6..922a115 100644 --- a/rainbowstream/colorset/larapaste.json +++ b/rainbowstream/colorset/larapaste.json @@ -27,6 +27,7 @@ "nick" : 37, "clock" : 184, "id" : 184, + "client" : 154, "favorited" : 154, "retweet_count" : 154, "favorite_count" : 202, diff --git a/rainbowstream/colorset/monokai.json b/rainbowstream/colorset/monokai.json index 6eac09f..c777eb2 100644 --- a/rainbowstream/colorset/monokai.json +++ b/rainbowstream/colorset/monokai.json @@ -27,6 +27,7 @@ "nick" : 112, "clock" : 57, "id" : 166, + "client" : 74, "favorited" : 50, "retweet_count" : 50, "favorite_count" : 198, diff --git a/rainbowstream/colorset/solarized.json b/rainbowstream/colorset/solarized.json index 7e77bb7..9053da8 100644 --- a/rainbowstream/colorset/solarized.json +++ b/rainbowstream/colorset/solarized.json @@ -27,6 +27,7 @@ "nick" : 64, "clock" : 32, "id" : 130, + "client" : 23, "favorited" : 64, "retweet_count" : 64, "favorite_count" : 124, diff --git a/rainbowstream/colorset/tomorrow_night.json b/rainbowstream/colorset/tomorrow_night.json index f48bdb7..309d889 100644 --- a/rainbowstream/colorset/tomorrow_night.json +++ b/rainbowstream/colorset/tomorrow_night.json @@ -27,6 +27,7 @@ "nick" : 67, "clock" : 58, "id" : 58, + "client" : 58, "favorited" : 97, "retweet_count" : 97, "favorite_count" : 166, diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 429bd27..dd32297 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -190,6 +190,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): favorited = t['favorited'] retweet_count = t['retweet_count'] favorite_count = t['favorite_count'] + client = t['source'] date = parser.parse(created_at) try: clock_format = c['FORMAT']['TWEET']['CLOCK_FORMAT'] @@ -215,6 +216,12 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): # Unescape HTML character text = unescape(text) + # Get client name + try: + client = client.split('>')[-2].split('<')[0] + except: + client = None + # Get expanded url try: expanded_url = [] @@ -330,6 +337,11 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): word = [wo for wo in formater.split() if '#id' in wo][0] delimiter = color_func(c['TWEET']['id'])(id.join(word.split('#id'))) formater = delimiter.join(formater.split(word)) + # Change client word + word = [wo for wo in formater.split() if '#client' in wo][0] + delimiter = color_func(c['TWEET']['client'])( + client.join(word.split('#client'))) + formater = delimiter.join(formater.split(word)) # Change retweet count word word = [wo for wo in formater.split() if '#rt_count' in wo][0] delimiter = color_func(c['TWEET']['retweet_count'])( diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 500c2db..49e3308 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -482,6 +482,24 @@ 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) + os.system("echo '%s' | pbcopy" % url) + printNicely(green('Copied tweet\'s url to clipboard.')) + + def delete(): """ Delete @@ -1394,6 +1412,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 +1695,7 @@ cmdset = [ 'rep', 'del', 'ufav', + 'share', 's', 'mes', 'show', @@ -1719,6 +1741,7 @@ funcset = [ reply, delete, unfavorite, + share, search, message, show, @@ -1777,6 +1800,7 @@ def listen(): [], # reply [], # delete [], # unfavorite + [], # url ['#'], # search ['@'], # message ['image'], # show image diff --git a/setup.py b/setup.py index dec267a..82eed6e 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '1.0.7' +version = '1.0.8' # Require install_requires = [ diff --git a/theme.md b/theme.md index a679141..4f1a603 100644 --- a/theme.md +++ b/theme.md @@ -25,15 +25,18 @@ Examples are available in "DECORATED_NAME" : 198, "CYCLE_COLOR" :[198,57,166,50,179,74,112], "TWEET" : { + "mynick" : 179, "nick" : 112, "clock" : 57, "id" : 166, + "client" : 74, "favorited" : 50, "retweet_count" : 50, "favorite_count" : 198, "rt" : 179, "link" : 74, "hashtag" : 198, + "mytweet" : 179, "keyword" : "on_light_green" }, @@ -46,8 +49,8 @@ Examples are available in "MESSAGE" : { "partner" : 112, "me" : 112, - "me_frame" : 74, "partner_frame" : 198, + "me_frame" : 74, "sender" : 112, "recipient" : 112, "to" : 50, @@ -144,6 +147,7 @@ Color reference can be found at * `nick` : color for other Twitter __username__. * `clock`: color for time of tweet. * `id`: color for tweet's id. + * `client`: color for used Twitter client. * `favorite`: color for the star symbol when a tweet is favorited by you. * `retweet_count`: color for retweets count. * `favorite_count`: color for favorites count. -- 2.25.1