From: Orakaro Date: Sat, 30 Aug 2014 06:31:27 +0000 (+0900) Subject: add notification command X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=commitdiff_plain;h=99cd1fba83efcd1dd6f01570ea79776b4e41f1cf;ds=sidebyside add notification command --- diff --git a/docs/conf.py b/docs/conf.py index 31dd0fe..21de618 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.3' +version = '0.9.4' # The full version, including alpha/beta/rc tags. -release = '0.9.3' +release = '0.9.4' # 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 a11e7da..fbf68f8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -112,34 +112,27 @@ Here is full list of supported command: **Explore Commands** -- ``trend`` will show global trending topics. ``trend US`` will show - trends in United States while ``trend JP Tokyo`` will show trends in - Tokyo/Japan. +- ``trend`` will show global trending topics. ``trend US`` will show trends in United States while ``trend JP Tokyo`` will show trends in Tokyo/Japan. -- ``home`` will show your timeline. ``home 10`` will print exactly 10 - tweets. +- ``home`` will show your timeline. ``home 10`` will print exactly 10 tweets. -- ``mentions`` will show mentions timeline. ``mentions 7`` will show 7 - mention tweets. +- ``notification`` will show your notification from the time you started RainbowStream. + +- ``mentions`` will show mentions timeline. ``mentions 7`` will show 7 mention tweets. - ``whois @dtvd88`` will show profile of @dtvd88. -- ``view @mdo`` will show @mdo ’s timeline. ``view @dmo 9`` will print - exactly 9 tweets. +- ``view @mdo`` will show @mdo ’s timeline. ``view @dmo 9`` will print exactly 9 tweets. -- ``s noah`` will search the word *‘noah’*. Result will come back with - highlight. Search can be performed with or without hashtag. +- ``s noah`` will search the word *‘noah’*. Result will come back with highlight. Search can be performed with or without hashtag. **Tweet Commands** -- ``t the rainbow is god's promise to noah`` will tweet exactly *‘the - rainbow is god’s promise to noah’*. +- ``t the rainbow is god's promise to noah`` will tweet exactly *‘the rainbow is god’s promise to noah’*. -- ``rt 12`` will retweet the tweet with *[id=12]*. You can see id of - each tweet beside the time. +- ``rt 12`` will retweet the tweet with *[id=12]*. You can see id of each tweet beside the time. -- ``quote 12`` will quote the tweet with *[id=12]*. If no extra text is added, - the quote will be cancelled. +- ``quote 12`` will quote the tweet with *[id=12]*. If no extra text is added, the quote will be cancelled. - ``allrt 12 20`` will list 20 newest retweets of the tweet with *[id=12]*. If the number of retweets is not specified, 5 newest retweets will be listed instead. @@ -153,11 +146,9 @@ Here is full list of supported command: - ``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. +- ``show image 12`` will show the image in tweet with *[id=12]* in your OS’s image viewer. -- ``open 12`` will open url in tweet with *[id=12]* in your - OS’s default browser. +- ``open 12`` will open url in tweet with *[id=12]* in your OS’s default browser. **Direct Messages Commands** @@ -171,8 +162,7 @@ Here is full list of supported command: **Friends and followers Commands** -- ``ls fl`` will list all your followers (people who are following - you). +- ``ls fl`` will list all your followers (people who are following you). - ``ls fr`` will list all your friends (people who you are following). @@ -220,21 +210,17 @@ Here is full list of supported command: **Switching Stream Commands** -- ``switch public #AKB48`` will switch current stream to public stream - and track keyword ``AKB48`` +- ``switch public #AKB48`` will switch current stream to public stream and track keyword ``AKB48`` -- ``switch public #AKB48 -f`` will do exactly as above but will ask you - to provide 2 list: +- ``switch public #AKB48 -f`` will do exactly as above but will ask you to provide 2 list: ``Only nicks`` decide what nicks will be include only. ``Ignore nicks``\ decide what nicks will be exclude. -- ``switch public #AKB48 -d`` will apply filter to *ONLY\_LIST* and - *IGNORE\_LIST*. You can setup 2 list above at ``config.py`` +- ``switch public #AKB48 -d`` will apply filter to *ONLY\_LIST* and *IGNORE\_LIST*. You can setup 2 list above at ``config.py`` -- ``switch mine`` will switch current stream to personal stream. ``-f`` - and ``-d`` will work as well. +- ``switch mine`` will switch current stream to personal stream. ``-f`` and ``-d`` will work as well. **Smart shell** diff --git a/rainbowstream/colorset/larapaste.json b/rainbowstream/colorset/larapaste.json index 495a63b..fd75cc6 100644 --- a/rainbowstream/colorset/larapaste.json +++ b/rainbowstream/colorset/larapaste.json @@ -37,6 +37,12 @@ "keyword" : "on_light_green" }, + "NOTIFICATION":{ + "source_nick" : 37, + "notify" : 202, + "clock" : 184 + }, + "MESSAGE" : { "partner" : 37, "me" : 37, diff --git a/rainbowstream/colorset/monokai.json b/rainbowstream/colorset/monokai.json index 68365ca..6eac09f 100644 --- a/rainbowstream/colorset/monokai.json +++ b/rainbowstream/colorset/monokai.json @@ -37,6 +37,12 @@ "keyword" : "on_light_green" }, + "NOTIFICATION":{ + "source_nick" : 112, + "notify" : 179, + "clock" : 57 + }, + "MESSAGE" : { "partner" : 112, "me" : 112, diff --git a/rainbowstream/colorset/solarized.json b/rainbowstream/colorset/solarized.json index 99863e5..7e77bb7 100644 --- a/rainbowstream/colorset/solarized.json +++ b/rainbowstream/colorset/solarized.json @@ -37,6 +37,12 @@ "keyword" : "on_light_green" }, + "NOTIFICATION":{ + "source_nick" : 64, + "notify" : 66, + "clock" : 32 + }, + "MESSAGE" : { "partner" : 64, "me" : 64, diff --git a/rainbowstream/colorset/tomorrow_night.json b/rainbowstream/colorset/tomorrow_night.json index d48b683..f48bdb7 100644 --- a/rainbowstream/colorset/tomorrow_night.json +++ b/rainbowstream/colorset/tomorrow_night.json @@ -37,6 +37,12 @@ "keyword" : "on_light_blue" }, + "NOTIFICATION":{ + "source_nick" : 67, + "notify" : 145, + "clock" : 58 + }, + "MESSAGE" : { "partner" : 67, "me" : 67, diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 9ce1897..3c0ce67 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -145,7 +145,7 @@ def color_func(func_name): return globals()[func_name] -def draw(t, keyword=None, humanize=True, fil=[], ig=[]): +def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]): """ Draw the rainbow """ @@ -311,6 +311,10 @@ def draw(t, keyword=None, humanize=True, fil=[], ig=[]): except: pass + # Add spaces in begining of line if this is inside a notification + if noti: + formater = '\n '.join(formater.split('\n')) + # Draw printNicely(formater) @@ -582,6 +586,220 @@ def print_message(m): printNicely(formater) +def notify_favorite(e): + """ + Notify a favorite event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + target_object = e['target_object'] + created_at = e['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + 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 + # Output + printNicely('') + printNicely(meta) + draw(t=target_object, noti=True) + + +def notify_unfavorite(e): + """ + Notify a unfavorite event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + target_object = e['target_object'] + created_at = e['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + notify = color_func(c['NOTIFICATION']['notify'])( + ' 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 + # Output + printNicely('') + printNicely(meta) + draw(t=target_object, noti=True) + + +def notify_follow(e): + """ + Notify a follow event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + created_at = e['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + 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 + # Output + printNicely('') + printNicely(meta) + + +def notify_list_member_added(e): + """ + Notify a list_member_added event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + target_object = [e['target_object']] # list of Twitter list + created_at = e['created_at'] + # Format + 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 ') + 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 + # Output + printNicely('') + printNicely(meta) + print_list(target_object, noti=True) + + +def notify_list_member_removed(e): + """ + Notify a list_member_removed event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + target_object = [e['target_object']] # list of Twitter list + created_at = e['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + notify = color_func(c['NOTIFICATION']['notify'])( + ' 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 + # Output + printNicely('') + printNicely(meta) + print_list(target_object, noti=True) + + +def notify_list_user_subscribed(e): + """ + Notify a list_user_subscribed event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + target_object = [e['target_object']] # list of Twitter list + created_at = e['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + notify = color_func(c['NOTIFICATION']['notify'])( + ' 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 + # Output + printNicely('') + printNicely(meta) + print_list(target_object, noti=True) + + +def notify_list_user_unsubscribed(e): + """ + Notify a list_user_unsubscribed event + """ + # Retrieve info + target = e['target'] + if target['screen_name'] != c['original_name']: + return + source = e['source'] + target_object = [e['target_object']] # list of Twitter list + created_at = e['created_at'] + # Format + source_user = cycle_color(source['name']) + \ + color_func(c['NOTIFICATION']['source_nick'])( + ' @' + source['screen_name']) + notify = color_func(c['NOTIFICATION']['notify'])( + ' 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 + # Output + printNicely('') + printNicely(meta) + print_list(target_object, noti=True) + + +def print_event(e): + """ + Notify an event + """ + event_dict = { + 'favorite': notify_favorite, + 'unfavorite': notify_unfavorite, + 'follow': notify_follow, + 'list_member_added': notify_list_member_added, + 'list_member_removed': notify_list_member_removed, + 'list_user_subscribed': notify_list_user_subscribed, + 'list_user_unsubscribed': notify_list_user_unsubscribed, + } + event_dict[e['event']](e) + + def show_profile(u): """ Show a profile @@ -680,7 +898,7 @@ def print_trends(trends): printNicely('') -def print_list(group): +def print_list(group, noti=False): """ Display a list """ @@ -705,11 +923,15 @@ def print_list(group): clock = arrow.get(date).to('local').humanize(locale=lang) clock = 'Created at ' + color_func(c['GROUP']['clock'])(clock) + prefix = ' ' * 2 + # Add spaces in begining of line if this is inside a notification + if noti: + prefix = ' ' * 2 + prefix # Create lines - line1 = ' ' * 2 + name + member + ' ' + subscriber - line2 = ' ' * 4 + description - line3 = ' ' * 4 + mode - line4 = ' ' * 4 + clock + line1 = prefix + name + member + ' ' + subscriber + line2 = prefix + ' ' * 2 + description + line3 = prefix + ' ' * 2 + mode + line4 = prefix + ' ' * 2 + clock # Display printNicely('') diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index fa66626..05bbeab 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -133,6 +133,8 @@ def init(args): g['themes'] = themes g['pause'] = False g['message_threads'] = {} + # Events + g['events'] = [] # Startup cmd g['cmd'] = '' # Semaphore init @@ -196,6 +198,18 @@ def home(): printNicely('') +def notification(): + """ + Show notifications + """ + if g['events']: + for e in g['events']: + print_event(e) + printNicely('') + else: + printNicely(magenta('Nothing at this time.')) + + def mentions(): """ Mentions timeline @@ -1226,6 +1240,8 @@ def help_discover(): light_green('trend JP Tokyo') + '.\n' usage += s * 2 + light_green('home') + ' will show your timeline. ' + \ light_green('home 7') + ' will show 7 tweets.\n' + usage += s * 2 + \ + light_green('notification') + ' will show your recent notification.\n' usage += s * 2 + light_green('mentions') + ' will show mentions timeline. ' + \ light_green('mentions 7') + ' will show 7 mention tweets.\n' usage += s * 2 + light_green('whois @mdo') + ' will show profile of ' + \ @@ -1535,6 +1551,7 @@ cmdset = [ 'switch', 'trend', 'home', + 'notification', 'view', 'mentions', 't', @@ -1579,6 +1596,7 @@ funcset = [ switch, trend, home, + notification, view, mentions, tweet, @@ -1636,6 +1654,7 @@ def listen(): ['public', 'mine'], # switch [], # trend [], # home + [], # notification ['@'], # view [], # mentions [], # tweet @@ -1825,6 +1844,9 @@ def stream(domain, args, name='Rainbow Stream'): while c['lock']: time.sleep(0.5) print_message(tweet['direct_message']) + elif tweet.get('event'): + g['events'].append(tweet) + print_event(tweet) except TwitterHTTPError: printNicely('') printNicely( diff --git a/setup.py b/setup.py index 71c9ae3..32fcadf 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '0.9.3' +version = '0.9.4' # Require install_requires = [ diff --git a/theme.md b/theme.md index 1ad272f..a679141 100644 --- a/theme.md +++ b/theme.md @@ -37,6 +37,12 @@ Examples are available in "keyword" : "on_light_green" }, + "NOTIFICATION":{ + "source_nick" : 112, + "notify" : 179, + "clock" : 57 + }, + "MESSAGE" : { "partner" : 112, "me" : 112, @@ -146,6 +152,10 @@ Color reference can be found at * `hashtag`: color for a hashtag. * `mytweet`: color for tweet's text from yourself. * `keyword`: color for highlighted keyword (in tweets search). +* `NOTIFICATION`: colors of notification events. + * `source_nick`: color for user's __username__. + * `notify`: color for notification message. + * `clock`: color for time of notification event. * `MESSAGE`: colors of parts in message's output. * `partner`: color for __partner__. * `me`: color for __authenticated user__.