Fix bug can not quote in Python 2, Fix #195
[rainbowstream.git] / rainbowstream / draw.py
index dd32297dd8d8da02781363b20dcbf6a0904e9ec6..ab202763c2bb6506d6d6655f78618be3330741ce 100644 (file)
@@ -7,6 +7,7 @@ import arrow
 import re
 import os
 
+from io import BytesIO
 from twitter.util import printNicely
 from functools import wraps
 from pyfiglet import figlet_format
@@ -272,7 +273,8 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
     if favorited:
         fav = color_func(c['TWEET']['favorited'])(u'\u2605')
 
-    tweet = text.split()
+    tweet = text.split(' ')
+    tweet = [x for x in tweet if x != '']
     # Replace url
     if expanded_url:
         for index in xrange(len(expanded_url)):
@@ -288,17 +290,18 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
         else x,
         tweet)
     # Highlight screen_name
-    tweet = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, tweet)
+    tweet = lmap(
+        lambda x: cycle_color(x) if x.lstrip().startswith('@') else x, tweet)
     # Highlight link
     tweet = lmap(
         lambda x: color_func(c['TWEET']['link'])(x)
-        if x.startswith('http')
+        if x.lstrip().startswith('http')
         else x,
         tweet)
     # Highlight hashtag
     tweet = lmap(
         lambda x: color_func(c['TWEET']['hashtag'])(x)
-        if x.startswith('#')
+        if x.lstrip().startswith('#')
         else x,
         tweet)
     # Highlight my tweet
@@ -307,11 +310,12 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
                  for x in tweet
                  if not any([
                      x == 'RT',
-                     x.startswith('http'),
-                     x.startswith('#')])
+                     x.lstrip().startswith('http'),
+                     x.lstrip().startswith('#')])
                  ]
     # Highlight keyword
     tweet = ' '.join(tweet)
+    tweet = '\n  '.join(tweet.split('\n'))
     if keyword:
         roj = re.search(keyword, tweet, re.IGNORECASE)
         if roj:
@@ -328,6 +332,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
         formater = nick.join(formater.split('#nick'))
         formater = fav.join(formater.split('#fav'))
         formater = tweet.join(formater.split('#tweet'))
+        formater = emojize(formater)
         # Change clock word
         word = [wo for wo in formater.split() if '#clock' in wo][0]
         delimiter = color_func(c['TWEET']['clock'])(
@@ -337,11 +342,6 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
         word = [wo for wo in formater.split() if '#id' in wo][0]
         delimiter = color_func(c['TWEET']['id'])(id.join(word.split('#id')))
         formater = delimiter.join(formater.split(word))
-        # Change client word
-        word = [wo for wo in formater.split() if '#client' in wo][0]
-        delimiter = color_func(c['TWEET']['client'])(
-            client.join(word.split('#client')))
-        formater = delimiter.join(formater.split(word))
         # Change retweet count word
         word = [wo for wo in formater.split() if '#rt_count' in wo][0]
         delimiter = color_func(c['TWEET']['retweet_count'])(
@@ -352,7 +352,11 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
         delimiter = color_func(c['TWEET']['favorite_count'])(
             str(favorite_count).join(word.split('#fa_count')))
         formater = delimiter.join(formater.split(word))
-        formater = emojize(formater)
+        # Change client word
+        word = [wo for wo in formater.split() if '#client' in wo][0]
+        delimiter = color_func(c['TWEET']['client'])(
+            client.join(word.split('#client')))
+        formater = delimiter.join(formater.split(word))
     except:
         pass
 
@@ -936,7 +940,7 @@ def show_profile(u):
     url = 'URL : ' + (color_func(c['PROFILE']['url'])(url) if url else '')
     date = parser.parse(created_at)
     clock = fallback_humanize(date)
-    clock = 'Join at ' + color_func(c['PROFILE']['clock'])(clock)
+    clock = 'Joined ' + color_func(c['PROFILE']['clock'])(clock)
 
     # Format
     line1 = u"{u:>{uw}}".format(
@@ -1077,7 +1081,6 @@ def format_quote(tweet):
         formater = c['QUOTE_FORMAT']
         formater = screen_name.join(formater.split('#owner'))
         formater = text.join(formater.split('#tweet'))
-        formater = u2str(formater)
         formater = emojize(formater)
     except:
         pass