From 38a6dc308c60aa43ad84f9ff0b9230540518ec28 Mon Sep 17 00:00:00 2001 From: Orakaro Date: Sat, 30 Aug 2014 23:36:18 +0900 Subject: [PATCH] add retweet of my tweet to notification --- docs/conf.py | 4 +- docs/index.rst | 2 + rainbowstream/colorset/config | 2 + rainbowstream/draw.py | 94 +++++++++++++++++++++++++++++------ rainbowstream/rainbow.py | 3 ++ setup.py | 2 +- 6 files changed, 89 insertions(+), 18 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 21de618..21df9bb 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.9.4' +version = '0.9.5' # The full version, including alpha/beta/rc tags. -release = '0.9.4' +release = '0.9.5' # 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 fbf68f8..85c855b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -327,6 +327,8 @@ You also can view or set a new value of every config key by ``config`` command ( - ``THREAD_MIN_WIDTH``: minimum width of a message frame. +- ``NOTIFY_FORMAT``: format of a notification. + - ``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 e0a3ba5..66c4c5d 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -28,6 +28,8 @@ "THREAD_META_RIGHT" : "#clock (#id)", // 'thread' frame's minimum width "THREAD_MIN_WIDTH" : 20, + // 'Notification' format + "NOTIFY_FORMAT" : " #source_user #notify #clock", // '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 3c0ce67..5357945 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -177,6 +177,14 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): try: text = 'RT @' + t['retweeted_status']['user']['screen_name'] + ': ' +\ t['retweeted_status']['text'] + # Display as a notification + target = t['retweeted_status']['user']['screen_name'] + if all([target == c['original_name'], not noti]): + # Add to evens for 'notification' command + t['event'] = 'retweet' + c['events'].append(t) + notify_retweet(t) + return except: pass @@ -314,6 +322,9 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): # Add spaces in begining of line if this is inside a notification if noti: formater = '\n '.join(formater.split('\n')) + # Reformat + if formater.startswith('\n'): + formater = formater[1:] # Draw printNicely(formater) @@ -586,6 +597,33 @@ def print_message(m): printNicely(formater) +def notify_retweet(t): + """ + Notify a retweet + """ + source = t['user'] + created_at = t['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + notify = color_func(c['NOTIFICATION']['notify'])( + 'retweeted your tweet') + date = parser.parse(created_at) + date = arrow.get(date).to('local') + lang, encode = locale.getdefaultlocale() + clock = arrow.get(date).to('local').humanize(locale=lang) + clock = color_func(c['NOTIFICATION']['clock'])(clock) + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) + # Output + printNicely('') + printNicely(meta) + draw(t=t['retweeted_status'], noti=True) + + def notify_favorite(e): """ Notify a favorite event @@ -601,13 +639,17 @@ def notify_favorite(e): source_user = cycle_color(source['name']) + \ color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) - notify = color_func(c['NOTIFICATION']['notify'])(' favorited your tweet ') + notify = color_func(c['NOTIFICATION']['notify'])( + 'favorited your tweet') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -630,13 +672,16 @@ def notify_unfavorite(e): color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) notify = color_func(c['NOTIFICATION']['notify'])( - ' unfavorited your tweet ') + 'unfavorited your tweet') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -657,13 +702,17 @@ def notify_follow(e): source_user = cycle_color(source['name']) + \ color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) - notify = color_func(c['NOTIFICATION']['notify'])(' followed you ') + notify = color_func(c['NOTIFICATION']['notify'])( + 'followed you') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -684,13 +733,17 @@ def notify_list_member_added(e): source_user = cycle_color(source['name']) + \ color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) - notify = color_func(c['NOTIFICATION']['notify'])(' added you to a list ') + notify = color_func(c['NOTIFICATION']['notify'])( + 'added you to a list') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -713,13 +766,16 @@ def notify_list_member_removed(e): color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) notify = color_func(c['NOTIFICATION']['notify'])( - ' removed you from a list ') + 'removed you from a list') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -742,13 +798,16 @@ def notify_list_user_subscribed(e): color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) notify = color_func(c['NOTIFICATION']['notify'])( - ' subscribed to your list ') + 'subscribed to your list') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -771,13 +830,16 @@ def notify_list_user_unsubscribed(e): color_func(c['NOTIFICATION']['source_nick'])( ' @' + source['screen_name']) notify = color_func(c['NOTIFICATION']['notify'])( - ' unsubscribed from your list ') + 'unsubscribed from your list') date = parser.parse(created_at) date = arrow.get(date).to('local') lang, encode = locale.getdefaultlocale() clock = arrow.get(date).to('local').humanize(locale=lang) clock = color_func(c['NOTIFICATION']['clock'])(clock) - meta = ' ' * 2 + source_user + notify + clock + meta = c['NOTIFY_FORMAT'] + meta = source_user.join(meta.split('#source_user')) + meta = notify.join(meta.split('#notify')) + meta = clock.join(meta.split('#clock')) # Output printNicely('') printNicely(meta) @@ -789,6 +851,7 @@ def print_event(e): Notify an event """ event_dict = { + 'retweet': notify_retweet, 'favorite': notify_favorite, 'unfavorite': notify_unfavorite, 'follow': notify_follow, @@ -940,7 +1003,8 @@ def print_list(group, noti=False): printNicely(line3) printNicely(line4) - printNicely('') + if not noti: + printNicely('') def show_calendar(month, date, rel): diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 05bbeab..08cdcb7 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -137,6 +137,8 @@ def init(args): g['events'] = [] # Startup cmd g['cmd'] = '' + # Retweet of mine events + c['events'] = [] # Semaphore init c['lock'] = False # Init tweet dict and message dict @@ -202,6 +204,7 @@ def notification(): """ Show notifications """ + g['events'] = g['events'] + c['events'] if g['events']: for e in g['events']: print_event(e) diff --git a/setup.py b/setup.py index 32fcadf..43343b3 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '0.9.4' +version = '0.9.5' # Require install_requires = [ -- 2.25.1