fix typo in help
[rainbowstream.git] / rainbowstream / draw.py
index 5dd078807b32946e40db1d561b123c51e693d4ef..00d3e252ec0766bdae4b03383ea07f8c554ab93c 100644 (file)
@@ -165,6 +165,8 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
     name = t['user']['name']
     created_at = t['created_at']
     favorited = t['favorited']
+    retweet_count = t['retweet_count']
+    favorite_count = t['favorite_count']
     date = parser.parse(created_at)
     date = date - datetime.timedelta(seconds=time.timezone)
     clock_format = '%Y/%m/%d %H:%M:%S'
@@ -233,7 +235,7 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
     tweet = text.split()
     # Replace url
     if expanded_url:
-        for index in range(len(expanded_url)):
+        for index in xrange(len(expanded_url)):
             tweet = lmap(
                 lambda x: expanded_url[index]
                 if x == url[index]
@@ -270,12 +272,13 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
             tweet = delimiter.join(ary)
 
     # Load config formater
+    formater = ''
     try:
         formater = c['FORMAT']['TWEET']['DISPLAY']
-        formater = name.join(formater.split("#name"))
-        formater = nick.join(formater.split("#nick"))
-        formater = fav.join(formater.split("#fav"))
-        formater = tweet.join(formater.split("#tweet"))
+        formater = name.join(formater.split('#name'))
+        formater = nick.join(formater.split('#nick'))
+        formater = fav.join(formater.split('#fav'))
+        formater = tweet.join(formater.split('#tweet'))
         # Change clock word
         word = [w for w in formater.split() if '#clock' in w][0]
         delimiter = color_func(c['TWEET']['clock'])(
@@ -285,9 +288,18 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
         word = [w for w in formater.split() if '#id' in w][0]
         delimiter = color_func(c['TWEET']['id'])(id.join(word.split('#id')))
         formater = delimiter.join(formater.split(word))
+        # Change retweet count word
+        word = [w for w in formater.split() if '#rt_count' in w][0]
+        delimiter = color_func(c['TWEET']['retweet_count'])(
+            str(retweet_count).join(word.split('#rt_count')))
+        formater = delimiter.join(formater.split(word))
+        # Change favorites count word
+        word = [w for w in formater.split() if '#fa_count' in w][0]
+        delimiter = color_func(c['TWEET']['favorite_count'])(
+            str(favorite_count).join(word.split('#fa_count')))
+        formater = delimiter.join(formater.split(word))
     except:
-        printNicely(red('Wrong format in config.'))
-        return
+        pass
 
     # Draw
     printNicely(formater)
@@ -534,5 +546,58 @@ def show_calendar(month, date, rel):
         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()