add retweet of my tweet to notification
authorOrakaro <nhatminh_179@hotmail.com>
Sat, 30 Aug 2014 14:36:18 +0000 (23:36 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Sat, 30 Aug 2014 14:36:18 +0000 (23:36 +0900)
docs/conf.py
docs/index.rst
rainbowstream/colorset/config
rainbowstream/draw.py
rainbowstream/rainbow.py
setup.py

index 21de618f3fbb1e518c20cf12540a758197d71211..21df9bbbe911bde101a28244542cb4c3401d3ef1 100644 (file)
@@ -48,9 +48,9 @@ copyright = u'2014, Vu Nhat Minh'
 # built documents.
 #
 # The short X.Y version.
 # built documents.
 #
 # The short X.Y version.
-version = '0.9.4'
+version = '0.9.5'
 # The full version, including alpha/beta/rc tags.
 # 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.
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
index fbf68f854f2f8edf682e8f38cc23f172a6264a75..85c855b11d856b02ce0cd95ca8bde2ae02ea949a 100644 (file)
@@ -327,6 +327,8 @@ You also can view or set a new value of every config key by ``config`` command (
 \r
 -  ``THREAD_MIN_WIDTH``: minimum width of a message frame.\r
 \r
 \r
 -  ``THREAD_MIN_WIDTH``: minimum width of a message frame.\r
 \r
+-  ``NOTIFY_FORMAT``: format of a notification.\r
+\r
 -  ``MESSAGES_DISPLAY``: default messages to display on 'inbox' or 'sent' command.\r
 \r
 -  ``TREND_MAX``: default trends to display on 'trend' command.\r
 -  ``MESSAGES_DISPLAY``: default messages to display on 'inbox' or 'sent' command.\r
 \r
 -  ``TREND_MAX``: default trends to display on 'trend' command.\r
index e0a3ba575e7df6a9ff9d1a429b9922db5d86dfd5..66c4c5dc7fd221ac3f6b408abac621a839811ae2 100644 (file)
@@ -28,6 +28,8 @@
     "THREAD_META_RIGHT" : "#clock (#id)",
     // 'thread' frame's minimum width
     "THREAD_MIN_WIDTH" : 20,
     "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
     // 'inbox','sent': default number of direct message
     "MESSAGES_DISPLAY" : 5,
     // 'trend': max trending topics
index 3c0ce67722f8f2c988576213fb1dc0985780b69b..535794522800236728d50a82fa9fd4877d75a9e5 100644 (file)
@@ -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']
     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
 
     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'))
     # 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)
 
     # Draw
     printNicely(formater)
@@ -586,6 +597,33 @@ def print_message(m):
     printNicely(formater)
 
 
     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
 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'])
     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)
     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)
     # 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'])(
         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)
     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)
     # 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'])
     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)
     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)
     # 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'])
     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)
     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)
     # 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'])(
         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)
     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)
     # 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'])(
         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)
     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)
     # 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'])(
         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)
     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)
     # Output
     printNicely('')
     printNicely(meta)
@@ -789,6 +851,7 @@ def print_event(e):
     Notify an event
     """
     event_dict = {
     Notify an event
     """
     event_dict = {
+        'retweet': notify_retweet,
         'favorite': notify_favorite,
         'unfavorite': notify_unfavorite,
         'follow': notify_follow,
         'favorite': notify_favorite,
         'unfavorite': notify_unfavorite,
         'follow': notify_follow,
@@ -940,7 +1003,8 @@ def print_list(group, noti=False):
         printNicely(line3)
         printNicely(line4)
 
         printNicely(line3)
         printNicely(line4)
 
-    printNicely('')
+    if not noti:
+        printNicely('')
 
 
 def show_calendar(month, date, rel):
 
 
 def show_calendar(month, date, rel):
index 05bbeabfa541b4742e5e6682fa148e12d2862b81..08cdcb7409cac73a65a3c2486fa138af92ce6678 100644 (file)
@@ -137,6 +137,8 @@ def init(args):
     g['events'] = []
     # Startup cmd
     g['cmd'] = ''
     g['events'] = []
     # Startup cmd
     g['cmd'] = ''
+    # Retweet of mine events
+    c['events'] = []
     # Semaphore init
     c['lock'] = False
     # Init tweet dict and message dict
     # Semaphore init
     c['lock'] = False
     # Init tweet dict and message dict
@@ -202,6 +204,7 @@ def notification():
     """
     Show notifications
     """
     """
     Show notifications
     """
+    g['events'] = g['events'] + c['events']
     if g['events']:
         for e in g['events']:
             print_event(e)
     if g['events']:
         for e in g['events']:
             print_event(e)
index 32fcadf189ff04b69765e174bc49ef89bff041ff..43343b3a39d2a0991cb3a685c125e0c23907acb3 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ import os
 import os.path
 
 # Bumped version
 import os.path
 
 # Bumped version
-version = '0.9.4'
+version = '0.9.5'
 
 # Require
 install_requires = [
 
 # Require
 install_requires = [