Commit 7a0a6fa4 authored by Ruxandra Burtica's avatar Ruxandra Burtica Committed by Joshua Roesslein
Browse files

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.
parent 564c6314
......@@ -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)
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment