Allow specifying the location of the twitter oauth and pocket oauth files. This shoul...
[rainbowstream.git] / rainbowstream / rainbow.py
index 21b1965766edc903df7220902dbfe67279dbfd70..187fc452b168419d982ba90e280890ceed618036 100644 (file)
@@ -89,6 +89,16 @@ def parse_arguments():
         '--proxy-type',
         default='SOCKS5',
         help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).')
+    parser.add_argument(
+        '-ta',
+        '--twitter-auth',
+        default=os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.rainbow_oauth',
+        help='Specify which OAuth profile to use for twitter. Default: ~/.rainbow_oauth.')
+    parser.add_argument(
+        '-pa',
+        '--pocket-auth',
+        default=os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.rainbow_pckt_oauth',
+        help='Specify which OAuth profile to use for pocket. Default: ~/.rainbow_pckt_oauth.')
     return parser.parse_args()
 
 
@@ -122,11 +132,7 @@ def authen():
     Authenticate with Twitter OAuth
     """
     # When using rainbow stream you must authorize.
-    twitter_credential = os.environ.get(
-        'HOME',
-        os.environ.get(
-            'USERPROFILE',
-            '')) + os.sep + '.rainbow_oauth'
+    twitter_credential = g['twitter_oauth_path']
     if not os.path.exists(twitter_credential):
         oauth_dance('Rainbow Stream',
                     CONSUMER_KEY,
@@ -144,12 +150,7 @@ def pckt_authen():
     """
     Authenticate with Pocket OAuth
     """
-    pocket_credential = os.environ.get(
-         'HOME',
-        os.environ.get(
-            'USERPROFILE',
-            '')) + os.sep + '.rainbow_pckt_oauth'
-
+    pocket_credential = g['pocket_oauth_path']
     if not os.path.exists(pocket_credential):
         request_token = Pocket.get_request_token(consumer_key=PCKT_CONSUMER_KEY)
         auth_url = Pocket.get_auth_url(code=request_token, redirect_uri="/")
@@ -238,6 +239,9 @@ def init(args):
     # Handle Ctrl C
     ctrl_c_handler = lambda signum, frame: quit()
     signal.signal(signal.SIGINT, ctrl_c_handler)
+    # Set OAuth file path (needs to happen before authen is called)
+    g['twitter_oauth_path'] = args.twitter_auth
+    g['pocket_oauth_path'] = args.pocket_auth
     # Upgrade notify
     upgrade_center()
     # Get name
@@ -330,7 +334,9 @@ 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, tweet_mode='extended')):
+    kwargs = {'count': num}
+    kwargs = add_tweetmode_parameter(kwargs)
+    for tweet in reversed(t.statuses.home_timeline(**kwargs)):
         draw(t=tweet)
     printNicely('')
 
@@ -355,7 +361,9 @@ 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, tweet_mode='extended')):
+    kwargs = {'count': num}
+    kwargs = add_tweetmode_parameter(kwargs)
+    for tweet in reversed(t.statuses.mentions_timeline(**kwargs)):
         draw(t=tweet)
     printNicely('')
 
@@ -398,8 +406,9 @@ def view():
             num = int(g['stuff'].split()[1])
         except:
             num = c['HOME_TWEET_NUM']
-        for tweet in reversed(
-                t.statuses.user_timeline(count=num, screen_name=user[1:], tweet_mode='extended')):
+        kwargs = {'count': num, 'screen_name': user[1:]}
+        kwargs = add_tweetmode_parameter(kwargs)
+        for tweet in reversed(t.statuses.user_timeline(**kwargs)):
             draw(t=tweet)
         printNicely('')
     else:
@@ -415,8 +424,10 @@ def view_my_tweets():
         num = int(g['stuff'])
     except:
         num = c['HOME_TWEET_NUM']
+    kwargs = {'count': num, 'screen_name': g['original_name']}
+    kwargs = add_tweetmode_parameter(kwargs)
     for tweet in reversed(
-            t.statuses.user_timeline(count=num, screen_name=g['original_name'], tweet_mode='extended')):
+            t.statuses.user_timeline(**kwargs)):
         draw(t=tweet)
     printNicely('')
 
@@ -436,12 +447,14 @@ def search():
         type = 'mixed'
     max_record = c['SEARCH_MAX_RECORD']
     count = min(max_record, 100)
+    kwargs = {
+        'q': query,
+        'type': type,
+        'count': count,
+    }
+    kwargs = add_tweetmode_parameter(kwargs)
     # Perform search
-    rel = t.search.tweets(
-        q=query,
-        type=type,
-        count=count
-    )['statuses']
+    rel = t.search.tweets(**kwargs)['statuses']
     # Return results
     if rel:
         printNicely('Newest tweets:')
@@ -535,7 +548,9 @@ def quote():
         printNicely(red('Sorry I can\'t understand.'))
         return
     tid = c['tweet_dict'][id]
-    tweet = t.statuses.show(id=tid, tweet_mode='extended')
+    kwargs = {'id': tid}
+    kwargs = add_tweetmode_parameter(kwargs)
+    tweet = t.statuses.show(**kwargs)
     # Get formater
     formater = format_quote(tweet)
     if not formater:
@@ -569,7 +584,9 @@ def allretweet():
     except:
         num = c['RETWEETS_SHOW_NUM']
     # Get result and display
-    rt_ary = t.statuses.retweets(id=tid, count=num, tweet_mode='extended')
+    kwargs = {'id': tid, 'count': num}
+    kwargs = add_tweetmode_parameter(kwargs)
+    rt_ary = t.statuses.retweets(**kwargs)
     if not rt_ary:
         printNicely(magenta('This tweet has no retweet.'))
         return
@@ -589,14 +606,17 @@ def conversation():
         printNicely(red('Sorry I can\'t understand.'))
         return
     tid = c['tweet_dict'][id]
-    tweet = t.statuses.show(id=tid, tweet_mode='extended')
+    kwargs = {'id': tid}
+    kwargs = add_tweetmode_parameter(kwargs)
+    tweet = t.statuses.show(**kwargs)
     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_mode='extended')
+        kwargs['id'] = prev_tid
+        tweet = t.statuses.show(**kwargs)
         prev_tid = tweet['in_reply_to_status_id']
         thread_ref.append(tweet)
 
@@ -663,7 +683,9 @@ def favorite():
     tid = c['tweet_dict'][id]
     t.favorites.create(_id=tid, include_entities=False)
     printNicely(green('Favorited.'))
-    draw(t.statuses.show(id=tid, tweet_mode='extended'))
+    kwargs = {'id': tid}
+    kwargs = add_tweetmode_parameter(kwargs)
+    draw(t.statuses.show(**kwargs))
     printNicely('')
 
 
@@ -680,7 +702,9 @@ def unfavorite():
     tid = c['tweet_dict'][id]
     t.favorites.destroy(_id=tid)
     printNicely(green('Okay it\'s unfavorited.'))
-    draw(t.statuses.show(id=tid, tweet_mode='extended'))
+    kwargs = {'id': tid}
+    kwargs = add_tweetmode_parameter(kwargs)
+    draw(t.statuses.show(**kwargs))
     printNicely('')
 
 
@@ -695,7 +719,9 @@ def share():
     except:
         printNicely(red('Tweet id is not valid.'))
         return
-    tweet = t.statuses.show(id=tid, tweet_mode='extended')
+    kwargs = {'id': tid}
+    kwargs = add_tweetmode_parameter(kwargs)
+    tweet = t.statuses.show(**kwargs)
     url = 'https://twitter.com/' + \
         tweet['user']['screen_name'] + '/status/' + str(tid)
     import platform