Added `tweet_mode='extended'` option to `t.statuses` calls
[rainbowstream.git] / rainbowstream / rainbow.py
index 93f711a5da202630d50fcfee1e41d17c460d1a5f..21b1965766edc903df7220902dbfe67279dbfd70 100644 (file)
@@ -330,7 +330,7 @@ def home():
     num = c['HOME_TWEET_NUM']
     if g['stuff'].isdigit():
         num = int(g['stuff'])
-    for tweet in reversed(t.statuses.home_timeline(count=num)):
+    for tweet in reversed(t.statuses.home_timeline(count=num, tweet_mode='extended')):
         draw(t=tweet)
     printNicely('')
 
@@ -355,7 +355,7 @@ def mentions():
     num = c['HOME_TWEET_NUM']
     if g['stuff'].isdigit():
         num = int(g['stuff'])
-    for tweet in reversed(t.statuses.mentions_timeline(count=num)):
+    for tweet in reversed(t.statuses.mentions_timeline(count=num, tweet_mode='extended')):
         draw(t=tweet)
     printNicely('')
 
@@ -399,7 +399,7 @@ def view():
         except:
             num = c['HOME_TWEET_NUM']
         for tweet in reversed(
-                t.statuses.user_timeline(count=num, screen_name=user[1:])):
+                t.statuses.user_timeline(count=num, screen_name=user[1:], tweet_mode='extended')):
             draw(t=tweet)
         printNicely('')
     else:
@@ -416,7 +416,7 @@ def view_my_tweets():
     except:
         num = c['HOME_TWEET_NUM']
     for tweet in reversed(
-            t.statuses.user_timeline(count=num, screen_name=g['original_name'])):
+            t.statuses.user_timeline(count=num, screen_name=g['original_name'], tweet_mode='extended')):
         draw(t=tweet)
     printNicely('')
 
@@ -465,7 +465,8 @@ def pocket():
     Add new link to Pocket along with tweet id
     """
     if not c['POCKET_SUPPORT']:
-        printNicely(red('Pocket isn\'t enabled.'))
+        printNicely(yellow('Pocket isn\'t enabled.'))
+        printNicely(yellow('You need to "config POCKET_SUPPORT = true"'))
         return
 
     # Get tweet infos
@@ -534,7 +535,7 @@ def quote():
         printNicely(red('Sorry I can\'t understand.'))
         return
     tid = c['tweet_dict'][id]
-    tweet = t.statuses.show(id=tid)
+    tweet = t.statuses.show(id=tid, tweet_mode='extended')
     # Get formater
     formater = format_quote(tweet)
     if not formater:
@@ -568,7 +569,7 @@ def allretweet():
     except:
         num = c['RETWEETS_SHOW_NUM']
     # Get result and display
-    rt_ary = t.statuses.retweets(id=tid, count=num)
+    rt_ary = t.statuses.retweets(id=tid, count=num, tweet_mode='extended')
     if not rt_ary:
         printNicely(magenta('This tweet has no retweet.'))
         return
@@ -588,14 +589,14 @@ def conversation():
         printNicely(red('Sorry I can\'t understand.'))
         return
     tid = c['tweet_dict'][id]
-    tweet = t.statuses.show(id=tid)
+    tweet = t.statuses.show(id=tid, tweet_mode='extended')
     limit = c['CONVERSATION_MAX']
     thread_ref = []
     thread_ref.append(tweet)
     prev_tid = tweet['in_reply_to_status_id']
     while prev_tid and limit:
         limit -= 1
-        tweet = t.statuses.show(id=prev_tid)
+        tweet = t.statuses.show(id=prev_tid, tweet_mode='extended')
         prev_tid = tweet['in_reply_to_status_id']
         thread_ref.append(tweet)
 
@@ -617,7 +618,12 @@ def reply():
     tid = c['tweet_dict'][id]
     user = t.statuses.show(id=tid)['user']['screen_name']
     status = ' '.join(g['stuff'].split()[1:])
-    status = '@' + user + ' ' + str2u(status)
+    # don't include own username for tweet chains
+    # for details see issue https://github.com/DTVD/rainbowstream/issues/163
+    if user == g['original_name']:
+        status = str2u(status)
+    else:
+        status = '@' + user + ' ' + str2u(status)
     t.statuses.update(status=status, in_reply_to_status_id=tid)
 
 
@@ -657,7 +663,7 @@ def favorite():
     tid = c['tweet_dict'][id]
     t.favorites.create(_id=tid, include_entities=False)
     printNicely(green('Favorited.'))
-    draw(t.statuses.show(id=tid))
+    draw(t.statuses.show(id=tid, tweet_mode='extended'))
     printNicely('')
 
 
@@ -674,7 +680,7 @@ def unfavorite():
     tid = c['tweet_dict'][id]
     t.favorites.destroy(_id=tid)
     printNicely(green('Okay it\'s unfavorited.'))
-    draw(t.statuses.show(id=tid))
+    draw(t.statuses.show(id=tid, tweet_mode='extended'))
     printNicely('')
 
 
@@ -689,7 +695,7 @@ def share():
     except:
         printNicely(red('Tweet id is not valid.'))
         return
-    tweet = t.statuses.show(id=tid)
+    tweet = t.statuses.show(id=tid, tweet_mode='extended')
     url = 'https://twitter.com/' + \
         tweet['user']['screen_name'] + '/status/' + str(tid)
     import platform
@@ -902,24 +908,41 @@ def ls():
     d = {'fl': 'followers', 'fr': 'friends'}
     next_cursor = -1
     rel = {}
+
+    printNicely('All ' + d[target] + ':')
+
     # Cursor loop
+    number_of_users = 0
     while next_cursor != 0:
+
         list = getattr(t, d[target]).list(
             screen_name=name,
             cursor=next_cursor,
             skip_status=True,
             include_entities=False,
         )
+
         for u in list['users']:
-            rel[u['name']] = '@' + u['screen_name']
+
+            number_of_users += 1
+
+            # Print out result
+            printNicely(   '  '                                               \
+                         + cycle_color( u['name'] )                           \
+                         + color_func(c['TWEET']['nick'])(    ' @'            \
+                                                           + u['screen_name'] \
+                                                           + ' ' ) )
+
         next_cursor = list['next_cursor']
-    # Print out result
-    printNicely('All: ' + str(len(rel)) + ' ' + d[target] + '.')
-    for name in rel:
-        user = '  ' + cycle_color(name)
-        user += color_func(c['TWEET']['nick'])(' ' + rel[name] + ' ')
-        printNicely(user)
 
+        # 300 users means 15 calls to the related API. The rate limit is 15
+        # calls per 15mn periods (see Twitter documentation).
+        if ( number_of_users % 300 == 0 ):
+            printNicely(light_yellow( 'We reached the limit of Twitter API.' ))
+            printNicely(light_yellow( 'You may need to wait about 15 minutes.' ))
+            break
+
+    printNicely('All: ' + str(number_of_users) + ' ' + d[target] + '.')
 
 def follow():
     """
@@ -1388,8 +1411,8 @@ def switch():
                 printNicely(light_magenta(guide))
                 only = raw_input('Only nicks [Ex: @xxx,@yy]: ')
                 ignore = raw_input('Ignore nicks [Ex: @xxx,@yy]: ')
-                args.filter = filter(None, only.split(','))
-                args.ignore = filter(None, ignore.split(','))
+                args.filter = list(filter(None, only.split(',')))
+                args.ignore = list(filter(None, ignore.split(',')))
         except:
             printNicely(red('Sorry, wrong format.'))
             return