From 7c437a0f019d51e4f2cd4dc4def34ce138f3d33b Mon Sep 17 00:00:00 2001 From: Orakaro Date: Sun, 17 Aug 2014 17:10:19 +0900 Subject: [PATCH] support quote format --- docs/conf.py | 4 ++-- docs/index.rst | 6 ++++++ rainbowstream/colorset/config | 2 ++ rainbowstream/draw.py | 8 +++---- rainbowstream/py3patch.py | 5 +++-- rainbowstream/rainbow.py | 40 +++++++++++++++++++++++++---------- setup.py | 2 +- 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a6b2510..5928a34 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 = '0.7.5' +version = '0.7.6' # The full version, including alpha/beta/rc tags. -release = '0.7.5' +release = '0.7.6' # 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 adf6578..a3a8420 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -311,6 +311,12 @@ You can view or set a new value of every config key by ``config`` command (See * - ``RETWEETS_SHOW_NUM``: default tweets to display on 'allrt' command. +- ``QUOTE_FORMAT``: format when quote a tweet + + + ``#comment``: Your own comment about the tweet + + ``#owner``: owner's username with '@' + + ``#tweet``: original tweet + - ``MESSAGES_DISPLAY``: default messages to display on 'inbox' or 'sent' command. - ``TREND_MAX``: default trends to display on 'trend' command. diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index da15583..9859d90 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -17,6 +17,8 @@ "HOME_TWEET_NUM" : 5, // 'allrt': default number of retweets "RETWEETS_SHOW_NUM" : 5, + // 'quote' format + "QUOTE_FORMAT" : "#comment RT #owner: #tweet", // 'inbox','sent': default number of direct message "MESSAGES_DISPLAY" : 5, // 'trend': max trending topics diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index b4f5883..248d1a9 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -275,10 +275,10 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]): formater = '' try: formater = c['FORMAT']['TWEET']['DISPLAY'] - formater = name.join(formater.split("#name")) - formater = nick.join(formater.split("#nick")) - formater = fav.join(formater.split("#fav")) - formater = tweet.join(formater.split("#tweet")) + formater = name.join(formater.split('#name')) + formater = nick.join(formater.split('#nick')) + formater = fav.join(formater.split('#fav')) + formater = tweet.join(formater.split('#tweet')) # Change clock word word = [w for w in formater.split() if '#clock' in w][0] delimiter = color_func(c['TWEET']['clock'])( diff --git a/rainbowstream/py3patch.py b/rainbowstream/py3patch.py index 660bd0b..b19bdca 100644 --- a/rainbowstream/py3patch.py +++ b/rainbowstream/py3patch.py @@ -23,9 +23,10 @@ unescape = HTMLParser().unescape # raw_input and map function behaviour if sys.version[0] == "2": lmap = lambda f, a: map(f, a) - unc = lambda x: x.decode('utf-8') + str2u = lambda x: x.decode('utf-8') + u2str = lambda x: x.encode('utf-8') else: xrange = range raw_input = input lmap = lambda f, a: list(map(f, a)) - unc = lambda x: x + str2u = u2str = lambda x: x diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index f1504ac..5d9e89a 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -312,6 +312,7 @@ def quote(): """ Quote a tweet """ + # Retrieve info t = Twitter(auth=authen()) try: id = int(g['stuff'].split()[0]) @@ -320,17 +321,34 @@ def quote(): return tid = c['tweet_dict'][id] tweet = t.statuses.show(id=tid) - screen_name = tweet['user']['screen_name'] + screen_name = '@' + tweet['user']['screen_name'] text = tweet['text'] - quote = '\"@' + screen_name + ': ' + text + '\"' - quote = quote.encode('utf8') - notice = light_magenta('Compose mode ') - notice += light_yellow('(Enter nothing will cancel the quote)') - notice += light_magenta(':') + # Validate quote format + if '#owner' not in c['QUOTE_FORMAT']: + printNicely(light_magenta('Quote should contains #owner')) + return + if '#comment' not in c['QUOTE_FORMAT']: + printNicely(light_magenta('Quote format should have #comment')) + return + # Notice + notice = light_magenta('Current quote format is: ') + notice += light_green(c['QUOTE_FORMAT']) printNicely(notice) - extra = raw_input(quote) - if extra: - t.statuses.update(status=quote + extra) + # Build formater + formater = '' + try: + formater = c['QUOTE_FORMAT'] + formater = screen_name.join(formater.split('#owner')) + formater = text.join(formater.split('#tweet')) + formater = u2str(formater) + except: + pass + # Get comment + prefix = light_magenta('Compose your ') + light_green('#comment: ') + comment = raw_input(prefix) + if comment: + quote = comment.join(formater.split('#comment')) + t.statuses.update(status = quote) else: printNicely(light_magenta('No text added.')) @@ -392,7 +410,7 @@ def reply(): tid = c['tweet_dict'][id] user = t.statuses.show(id=tid)['user']['screen_name'] status = ' '.join(g['stuff'].split()[1:]) - status = '@' + user + ' ' + unc(status) + status = '@' + user + ' ' + str2u(status) t.statuses.update(status=status, in_reply_to_status_id=tid) @@ -1742,7 +1760,7 @@ 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']) + unc(current_buffer)) + g['decorated_name'](c['PREFIX']) + str2u(current_buffer)) sys.stdout.flush() elif not c['HIDE_PROMPT']: sys.stdout.write(g['decorated_name'](c['PREFIX'])) diff --git a/setup.py b/setup.py index 90653fd..043b9c5 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '0.7.5' +version = '0.7.6' # Require install_requires = [ -- 2.25.1