Skip to content

Commit

Permalink
Merge pull request #209 from Lertsenem/pr-lsratelimit
Browse files Browse the repository at this point in the history
Avoid 'Rate limit exceeded' error on 'ls' command
  • Loading branch information
dtvd authored Dec 11, 2016
2 parents 8f6463c + 787643b commit cc92df2
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions rainbowstream/rainbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down

0 comments on commit cc92df2

Please sign in to comment.