From fdf25db8fdb3807e2d43431de54e9fc708e18c2f Mon Sep 17 00:00:00 2001 From: drselump14 Date: Tue, 10 Jan 2017 10:47:19 +0900 Subject: [PATCH 1/2] render quoted tweet like twitter.com #caution: need to set quoted_status color on colorset --- rainbowstream/colorset/larapaste.json | 1 + rainbowstream/colorset/monokai.json | 1 + rainbowstream/colorset/solarized.json | 1 + rainbowstream/colorset/tomorrow_night.json | 1 + rainbowstream/draw.py | 31 ++++++++++++++++------ 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/rainbowstream/colorset/larapaste.json b/rainbowstream/colorset/larapaste.json index 922a115a..943fe8c5 100644 --- a/rainbowstream/colorset/larapaste.json +++ b/rainbowstream/colorset/larapaste.json @@ -31,6 +31,7 @@ "favorited" : 154, "retweet_count" : 154, "favorite_count" : 202, + "quoted_status" : "red", "rt" : 202, "link" : 154, "hashtag" : 37, diff --git a/rainbowstream/colorset/monokai.json b/rainbowstream/colorset/monokai.json index c777eb2a..df4c795d 100644 --- a/rainbowstream/colorset/monokai.json +++ b/rainbowstream/colorset/monokai.json @@ -31,6 +31,7 @@ "favorited" : 50, "retweet_count" : 50, "favorite_count" : 198, + "quoted_status" : "red", "rt" : 179, "link" : 74, "hashtag" : 198, diff --git a/rainbowstream/colorset/solarized.json b/rainbowstream/colorset/solarized.json index 9053da8a..e79da274 100644 --- a/rainbowstream/colorset/solarized.json +++ b/rainbowstream/colorset/solarized.json @@ -31,6 +31,7 @@ "favorited" : 64, "retweet_count" : 64, "favorite_count" : 124, + "quoted_status" : "red", "rt" : 66, "link" : 23, "hashtag" : 64, diff --git a/rainbowstream/colorset/tomorrow_night.json b/rainbowstream/colorset/tomorrow_night.json index 309d889d..57ea80ac 100644 --- a/rainbowstream/colorset/tomorrow_night.json +++ b/rainbowstream/colorset/tomorrow_night.json @@ -31,6 +31,7 @@ "favorited" : 97, "retweet_count" : 97, "favorite_count" : 166, + "quoted_status" : "red", "rt" : 145, "link" : 30, "hashtag" : 67, diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 75e75772..8bb14bd5 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -185,6 +185,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): # Retrieve tweet tid = t['id'] text = t['text'] + quoted_status = '' screen_name = t['user']['screen_name'] name = t['user']['name'] created_at = t['created_at'] @@ -214,9 +215,17 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): except: pass + # Pull quoted status + try: + quoted_status = ' ++++++++++++ \n' +\ + ' ' + t['quoted_status']['user']['name'] + ' @' + t['quoted_status']['user']['screen_name'] + '\n ' +\ + ' ' + t['quoted_status']['text'] + '\n +++++++++++ \n' + quoted_status = unescape(quoted_status) + except: + pass + # Unescape HTML character text = unescape(text) - # Get client name try: client = client.split('>')[-2].split('<')[0] @@ -332,6 +341,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): formater = nick.join(formater.split('#nick')) formater = fav.join(formater.split('#fav')) formater = tweet.join(formater.split('#tweet')) + formater = color_func(c['TWEET']['quoted_status'])(quoted_status).join(formater.split('#quoted_status')) formater = emojize(formater) # Change clock word word = [wo for wo in formater.split() if '#clock' in wo][0] @@ -370,14 +380,19 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): # Draw printNicely(formater) + # Display Image - if c['IMAGE_ON_TERM'] and media_url: - for mu in media_url: - try: - response = requests.get(mu) - image_to_display(BytesIO(response.content)) - except Exception: - printNicely(red('Sorry, image link is broken')) + if media_url: + if c['IMAGE_ON_TERM']: + for mu in media_url: + try: + response = requests.get(mu) + image_to_display(BytesIO(response.content)) + except Exception as e: + print e + printNicely(red('Sorry, image link is broken')) + else: + printNicely(red(' Image available')) def print_threads(d): From f5f7e1599fb86fc9ba5016a87f864110215e46e2 Mon Sep 17 00:00:00 2001 From: Kris Date: Tue, 10 Jan 2017 15:49:36 +0900 Subject: [PATCH 2/2] Update config --- rainbowstream/colorset/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index 54b76ff0..fdd58483 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -57,7 +57,7 @@ "FORMAT": { "TWEET": { "CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S", - "DISPLAY" : "\n #name #nick #clock \n \u267A:#rt_count \u2665:#fa_count id:#id via #client #fav\n #tweet" + "DISPLAY" : "\n #name #nick #clock \n \u267A:#rt_count \u2665:#fa_count id:#id via #client #fav\n #tweet #quoted_status" }, "MESSAGE": { "CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S",