From: Orakaro Date: Sun, 11 Dec 2016 13:25:58 +0000 (+0900) Subject: Merge pull request #209 from Lertsenem/pr-lsratelimit X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=commitdiff_plain;h=cc92df2b3cb52d5becce93f443fc0cf6c5761c63;hp=8f6463c221697459f8d2186025e137153d5f8c69 Merge pull request #209 from Lertsenem/pr-lsratelimit Avoid 'Rate limit exceeded' error on 'ls' command --- diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 024e51b..118667c 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -908,24 +908,40 @@ 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( '(waiting 16mn for rate limits reasons...)' ) + time.sleep(16*60) + + printNicely('All: ' + str(number_of_users) + ' ' + d[target] + '.') def follow(): """