'--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()
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,
"""
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="/")
# 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
num = c['HOME_TWEET_NUM']
if g['stuff'].isdigit():
num = int(g['stuff'])
- for tweet in reversed(t.statuses.home_timeline(count=num)):
+ kwargs = {'count': num}
+ kwargs = add_tweetmode_parameter(kwargs)
+ for tweet in reversed(t.statuses.home_timeline(**kwargs)):
draw(t=tweet)
printNicely('')
num = c['HOME_TWEET_NUM']
if g['stuff'].isdigit():
num = int(g['stuff'])
- for tweet in reversed(t.statuses.mentions_timeline(count=num)):
+ kwargs = {'count': num}
+ kwargs = add_tweetmode_parameter(kwargs)
+ for tweet in reversed(t.statuses.mentions_timeline(**kwargs)):
draw(t=tweet)
printNicely('')
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:])):
+ 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:
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'])):
+ t.statuses.user_timeline(**kwargs)):
draw(t=tweet)
printNicely('')
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:')
printNicely(red('Sorry I can\'t understand.'))
return
tid = c['tweet_dict'][id]
- tweet = t.statuses.show(id=tid)
+ kwargs = {'id': tid}
+ kwargs = add_tweetmode_parameter(kwargs)
+ tweet = t.statuses.show(**kwargs)
# Get formater
formater = format_quote(tweet)
if not formater:
except:
num = c['RETWEETS_SHOW_NUM']
# Get result and display
- rt_ary = t.statuses.retweets(id=tid, count=num)
+ 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
printNicely(red('Sorry I can\'t understand.'))
return
tid = c['tweet_dict'][id]
- tweet = t.statuses.show(id=tid)
+ 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)
+ kwargs['id'] = prev_tid
+ tweet = t.statuses.show(**kwargs)
prev_tid = tweet['in_reply_to_status_id']
thread_ref.append(tweet)
tid = c['tweet_dict'][id]
t.favorites.create(_id=tid, include_entities=False)
printNicely(green('Favorited.'))
- draw(t.statuses.show(id=tid))
+ kwargs = {'id': tid}
+ kwargs = add_tweetmode_parameter(kwargs)
+ draw(t.statuses.show(**kwargs))
printNicely('')
tid = c['tweet_dict'][id]
t.favorites.destroy(_id=tid)
printNicely(green('Okay it\'s unfavorited.'))
- draw(t.statuses.show(id=tid))
+ kwargs = {'id': tid}
+ kwargs = add_tweetmode_parameter(kwargs)
+ draw(t.statuses.show(**kwargs))
printNicely('')
except:
printNicely(red('Tweet id is not valid.'))
return
- tweet = t.statuses.show(id=tid)
+ 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
# 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( '(waiting 16mn for rate limits reasons...)' )
- time.sleep(16*60)
+ 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] + '.')