preview quote format
authorvunhat_minh <vunhat_minh@dwango.co.jp>
Mon, 18 Aug 2014 03:56:10 +0000 (12:56 +0900)
committervunhat_minh <vunhat_minh@dwango.co.jp>
Mon, 18 Aug 2014 03:56:10 +0000 (12:56 +0900)
docs/conf.py
rainbowstream/draw.py
rainbowstream/rainbow.py
setup.py

index 98023df03a37d845a26e39eab4566d65b4eb13a6..0b9888b0e9a59fb6fcaecb19042bc79624148057 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.7.7'
+version = '0.7.8'
 # The full version, including alpha/beta/rc tags.
 # 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.
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
index 248d1a92f2b9112ca09bc3df8cc9504202c39fbd..00d3e252ec0766bdae4b03383ea07f8c554ab93c 100644 (file)
@@ -546,5 +546,58 @@ def show_calendar(month, date, rel):
         printNicely(' '.join(ary))
 
 
         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()
 # Start the color cycle
 start_cycle()
index 71310a9e50d289fc02255595d15b6fa10d0f4c1b..7add5574641a56a760b0826768fa58fb9e9ddc62 100644 (file)
@@ -312,7 +312,7 @@ def quote():
     """
     Quote a tweet
     """
     """
     Quote a tweet
     """
-    # Retrieve info
+    # Get tweet
     t = Twitter(auth=authen())
     try:
         id = int(g['stuff'].split()[0])
     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)
         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
         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'))
     # 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.'))
 
     else:
         printNicely(light_magenta('No text added.'))
 
index c1200cdde30838562ac1f41de2950189cc82e86d..e3532579bb86e416db9852ff9be941c7ee7f32ed 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.7.7'
+version = '0.7.8'
 
 # Require
 install_requires = [
 
 # Require
 install_requires = [