X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=rainbowstream%2Frainbow.py;h=2056c32c1528b43c34984b4b0045bcf9f6687a44;hb=cb1d7ee5cd7d1e5e7369286ea7d1dd5257c33970;hp=e0668c32522506195414415a551030659f1a56fb;hpb=787643bddacce47de1c0faafeaf1fa4c2e67b4f9;p=rainbowstream.git diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index e0668c3..2056c32 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -330,7 +330,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)): + kwargs = {'count': num} + kwargs = add_tweetmode_parameter(kwargs) + for tweet in reversed(t.statuses.home_timeline(**kwargs)): draw(t=tweet) printNicely('') @@ -355,7 +357,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)): + kwargs = {'count': num} + kwargs = add_tweetmode_parameter(kwargs) + for tweet in reversed(t.statuses.mentions_timeline(**kwargs)): draw(t=tweet) printNicely('') @@ -398,8 +402,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:])): + 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 +420,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'])): + t.statuses.user_timeline(**kwargs)): draw(t=tweet) printNicely('') @@ -436,16 +443,18 @@ 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:') - for i in reversed(xrange(count)): + for i in reversed(xrange(min(len(rel), count))): draw(t=rel[i], keyword=query) printNicely('') else: @@ -535,7 +544,9 @@ def quote(): 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: @@ -569,7 +580,9 @@ def allretweet(): 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 @@ -589,14 +602,17 @@ def conversation(): 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) @@ -618,7 +634,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) @@ -658,7 +679,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)) + kwargs = {'id': tid} + kwargs = add_tweetmode_parameter(kwargs) + draw(t.statuses.show(**kwargs)) printNicely('') @@ -675,7 +698,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)) + kwargs = {'id': tid} + kwargs = add_tweetmode_parameter(kwargs) + draw(t.statuses.show(**kwargs)) printNicely('') @@ -690,7 +715,9 @@ def share(): 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 @@ -933,8 +960,9 @@ def ls(): # 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] + '.')