From b7c9c57089a6af1d818b72bbab96a7f15871c0d1 Mon Sep 17 00:00:00 2001 From: vunhat_minh Date: Mon, 18 Aug 2014 12:56:10 +0900 Subject: [PATCH] preview quote format --- docs/conf.py | 4 +-- rainbowstream/draw.py | 53 ++++++++++++++++++++++++++++++++++++++++ rainbowstream/rainbow.py | 28 ++++----------------- setup.py | 2 +- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 98023df..0b9888b 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.7' +version = '0.7.8' # The full version, including alpha/beta/rc tags. -release = '0.7.7' +release = '0.7.8' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 248d1a9..00d3e25 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -546,5 +546,58 @@ def show_calendar(month, date, rel): printNicely(' '.join(ary)) +def format_quote(tweet): + """ + Quoting format + """ + # Retrieve info + screen_name = '@' + tweet['user']['screen_name'] + text = tweet['text'] + # Validate quote format + if '#owner' not in c['QUOTE_FORMAT']: + printNicely(light_magenta('Quote should contains #owner')) + return False + if '#comment' not in c['QUOTE_FORMAT']: + printNicely(light_magenta('Quote format should have #comment')) + return False + # 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 + # Highlight like a tweet + formater = formater.split() + formater = lmap( + lambda x: light_green(x) + if x == '#comment' + else x, + formater) + formater = lmap( + lambda x: color_func(c['TWEET']['rt'])(x) + if x == 'RT' + else x, + formater) + formater = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, formater) + formater = lmap( + lambda x: color_func(c['TWEET']['link'])(x) + if x[0:4] == 'http' + else x, + formater) + formater = lmap( + lambda x: color_func(c['TWEET']['hashtag'])(x) + if x.startswith('#') + else x, + formater) + formater = ' '.join(formater) + # Notice + notice = light_magenta('Quoting: "') + formater + light_magenta('"') + printNicely(notice) + return formater + + # Start the color cycle start_cycle() diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 71310a9..7add557 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -312,7 +312,7 @@ def quote(): """ Quote a tweet """ - # Retrieve info + # Get tweet t = Twitter(auth=authen()) try: id = int(g['stuff'].split()[0]) @@ -321,34 +321,16 @@ def quote(): return tid = c['tweet_dict'][id] tweet = t.statuses.show(id=tid) - screen_name = '@' + tweet['user']['screen_name'] - text = tweet['text'] - # Validate quote format - if '#owner' not in c['QUOTE_FORMAT']: - printNicely(light_magenta('Quote should contains #owner')) + # Get formater + formater = format_quote(tweet) + if not formater: 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) - # 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) + t.statuses.update(status=quote) else: printNicely(light_magenta('No text added.')) diff --git a/setup.py b/setup.py index c1200cd..e353257 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '0.7.7' +version = '0.7.8' # Require install_requires = [ -- 2.25.1