Handling the rate limit using cursors
=====================================
-Since cursors raise ``RateLimitError``\ s in their ``next()`` method,
+Since cursors raise ``RateLimitError``\ s while iterating,
handling them can be done by wrapping the cursor in an iterator.
Running this snippet will print all users you follow that themselves follow
def limit_handled(cursor):
while True:
try:
- yield cursor.next()
+ yield next(cursor)
except tweepy.RateLimitError:
time.sleep(15 * 60)
@tape.use_cassette('testcursornext.json')
def testcursornext(self):
"""
- Test cursor.next() behavior, id being passed correctly.
+ Test next(cursor) behavior, id being passed correctly.
Regression test for issue #518
"""
cursor = Cursor(self.api.user_timeline, id='Twitter').items(5)
- status = cursor.next()
+ status = next(cursor)
self.assertEqual(status.user.screen_name, 'Twitter')
raise StopIteration
if self.current_page is None or self.page_index == len(self.current_page) - 1:
# Reached end of current page, get the next page...
- self.current_page = self.page_iterator.next()
+ self.current_page = next(self.page_iterator)
while len(self.current_page) == 0:
- self.current_page = self.page_iterator.next()
+ self.current_page = next(self.page_iterator)
self.page_index = -1
self.page_index += 1
self.num_tweets += 1