Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
d1f2dc24
Commit
d1f2dc24
authored
Jun 16, 2013
by
Joshua Roesslein
Browse files
Fix a bug in cursors and tweak tests.
parent
e094ae72
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_cursors.py
View file @
d1f2dc24
...
...
@@ -8,8 +8,6 @@ class TweepyCursorTests(unittest.TestCase):
def
setUp
(
self
):
self
.
api
=
API
(
create_auth
())
self
.
api
.
retry_count
=
2
self
.
api
.
retry_delay
=
5
def
testidcursoritems
(
self
):
items
=
list
(
Cursor
(
self
.
api
.
user_timeline
).
items
(
25
))
...
...
@@ -20,16 +18,16 @@ class TweepyCursorTests(unittest.TestCase):
self
.
assertEqual
(
len
(
pages
),
5
)
def
testcursorcursoritems
(
self
):
items
=
list
(
Cursor
(
self
.
api
.
friends_ids
).
items
())
self
.
assert
_
(
len
(
items
)
>
0
)
items
=
list
(
Cursor
(
self
.
api
.
friends_ids
).
items
(
10
))
self
.
assert
Equal
(
len
(
items
)
,
1
0
)
items
=
list
(
Cursor
(
self
.
api
.
followers_ids
,
'twitter'
).
items
(
3
0
))
self
.
assert
_
(
len
(
items
)
==
3
0
)
items
=
list
(
Cursor
(
self
.
api
.
followers_ids
,
'twitter'
).
items
(
1
0
))
self
.
assert
Equal
(
len
(
items
)
,
1
0
)
def
testcursorcursorpages
(
self
):
pages
=
list
(
Cursor
(
self
.
api
.
friends_ids
).
pages
())
self
.
assert_
(
len
(
pages
)
>
0
)
pages
=
list
(
Cursor
(
self
.
api
.
friends_ids
).
pages
(
1
))
self
.
assert_
(
len
(
pages
)
==
1
)
pages
=
list
(
Cursor
(
self
.
api
.
followers_ids
,
'twitter'
).
pages
(
5
))
self
.
assert_
(
len
(
pages
)
==
5
)
pages
=
list
(
Cursor
(
self
.
api
.
followers_ids
,
'twitter'
).
pages
(
1
))
self
.
assert_
(
len
(
pages
)
==
1
)
tweepy/cursor.py
View file @
d1f2dc24
...
...
@@ -84,9 +84,13 @@ class IdIterator(BaseIterator):
BaseIterator
.
__init__
(
self
,
method
,
args
,
kargs
)
self
.
max_id
=
kargs
.
get
(
'max_id'
)
self
.
since_id
=
kargs
.
get
(
'since_id'
)
self
.
count
=
0
def
next
(
self
):
"""Fetch a set of items with IDs less than current set."""
if
self
.
limit
and
self
.
limit
==
self
.
count
:
raise
StopIteration
# max_id is inclusive so decrement by one
# to avoid requesting duplicate items.
max_id
=
self
.
since_id
-
1
if
self
.
max_id
else
None
...
...
@@ -95,16 +99,21 @@ class IdIterator(BaseIterator):
raise
StopIteration
self
.
max_id
=
data
.
max_id
self
.
since_id
=
data
.
since_id
self
.
count
+=
1
return
data
def
prev
(
self
):
"""Fetch a set of items with IDs greater than current set."""
if
self
.
limit
and
self
.
limit
==
self
.
count
:
raise
StopIteration
since_id
=
self
.
max_id
data
=
self
.
method
(
since_id
=
since_id
,
*
self
.
args
,
**
self
.
kargs
)
if
len
(
data
)
==
0
:
raise
StopIteration
self
.
max_id
=
data
.
max_id
self
.
since_id
=
data
.
since_id
self
.
count
+=
1
return
data
class
PageIterator
(
BaseIterator
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment