Add support for extended tweets in twitter.statuses calls
[rainbowstream.git] / rainbowstream / draw.py
index a94750682dda5753ead9be7092acc3a48cad3e90..fcc976c336f03097f6cef926c26e6113373a0386 100644 (file)
@@ -7,6 +7,7 @@ import arrow
 import re
 import os
 
 import re
 import os
 
+from io import BytesIO
 from twitter.util import printNicely
 from functools import wraps
 from pyfiglet import figlet_format
 from twitter.util import printNicely
 from functools import wraps
 from pyfiglet import figlet_format
@@ -183,7 +184,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
 
     # Retrieve tweet
     tid = t['id']
 
     # Retrieve tweet
     tid = t['id']
-    text = t['text']
+    text = t.get('full_text', t.get('text'))
     screen_name = t['user']['screen_name']
     name = t['user']['name']
     created_at = t['created_at']
     screen_name = t['user']['screen_name']
     name = t['user']['name']
     created_at = t['created_at']
@@ -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')
 
     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)):
     # 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
         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)
     # 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)
         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
         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',
                  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)
                  ]
     # Highlight keyword
     tweet = ' '.join(tweet)
+    tweet = '\n  '.join(tweet.split('\n'))
     if keyword:
         roj = re.search(keyword, tweet, re.IGNORECASE)
         if roj:
     if keyword:
         roj = re.search(keyword, tweet, re.IGNORECASE)
         if roj:
@@ -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)
     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(
 
     # Format
     line1 = u"{u:>{uw}}".format(
@@ -1062,8 +1066,10 @@ def format_quote(tweet):
     Quoting format
     """
     # Retrieve info
     Quoting format
     """
     # Retrieve info
-    screen_name = '@' + tweet['user']['screen_name']
-    text = tweet['text']
+    screen_name = tweet['user']['screen_name']
+    text        = tweet['text']
+    tid         = str( tweet['id'] )
+
     # Validate quote format
     if '#owner' not in c['QUOTE_FORMAT']:
         printNicely(light_magenta('Quote should contains #owner'))
     # Validate quote format
     if '#owner' not in c['QUOTE_FORMAT']:
         printNicely(light_magenta('Quote should contains #owner'))
@@ -1071,13 +1077,16 @@ def format_quote(tweet):
     if '#comment' not in c['QUOTE_FORMAT']:
         printNicely(light_magenta('Quote format should have #comment'))
         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']
     # Build formater
     formater = ''
     try:
         formater = c['QUOTE_FORMAT']
-        formater = screen_name.join(formater.split('#owner'))
-        formater = text.join(formater.split('#tweet'))
-        formater = u2str(formater)
+
+        formater = formater.replace('#owner', screen_name)
+        formater = formater.replace('#tweet', text)
+        formater = formater.replace('#tid',   tid)
+
         formater = emojize(formater)
     except:
         pass
         formater = emojize(formater)
     except:
         pass