From: Ruxandra Burtica Date: Fri, 27 Dec 2013 18:04:19 +0000 (-0600) Subject: Support setting the starting cursor position... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7a0a6fa40c04a60f333541d094aeced5d7dc63f4;p=tweepy.git Support setting the starting cursor position... Ex: Cursor(api.friends_ids, cursor=123456) The cursor will start iterating at position 12456 rather than the first "page" (position -1). Based on original work by Ruxandra Burtica in Pull request #194. --- diff --git a/tests/test_cursors.py b/tests/test_cursors.py index 44e7893..fb04847 100644 --- a/tests/test_cursors.py +++ b/tests/test_cursors.py @@ -31,3 +31,8 @@ class TweepyCursorTests(unittest.TestCase): pages = list(Cursor(self.api.followers_ids, 'twitter').pages(1)) self.assert_(len(pages) == 1) + def testcursorsetstartcursor(self): + c = Cursor(self.api.friends_ids, cursor=123456) + self.assertEqual(c.iterator.next_cursor, 123456) + self.assertFalse('cursor' in c.iterator.kargs) + diff --git a/tweepy/cursor.py b/tweepy/cursor.py index 9061bfd..4c06f17 100644 --- a/tweepy/cursor.py +++ b/tweepy/cursor.py @@ -53,8 +53,9 @@ class CursorIterator(BaseIterator): def __init__(self, method, args, kargs): BaseIterator.__init__(self, method, args, kargs) - self.next_cursor = -1 - self.prev_cursor = 0 + start_cursor = kargs.pop('cursor', None) + self.next_cursor = start_cursor or -1 + self.prev_cursor = start_cursor or 0 self.count = 0 def next(self):