Some corrections for twython cursor
It’s now working properly for search and get_user_timeline. I didn’t test other functions though.
This commit is contained in:
parent
f4496ec8b2
commit
faeebad921
1 changed files with 9 additions and 13 deletions
|
|
@ -430,19 +430,15 @@ class Twython(EndpointsMixin, object):
|
||||||
if function.iter_mode == 'cursor' and content['next_cursor_str'] == '0':
|
if function.iter_mode == 'cursor' and content['next_cursor_str'] == '0':
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
try:
|
if function.iter_mode == 'id':
|
||||||
if function.iter_mode == 'id':
|
if hasattr(function, 'iter_key') and len(content[function.iter_key]) > 0:
|
||||||
if not 'max_id' in params:
|
params['max_id'] = min(content[function.iter_key], key=lambda i: i['id'])['id'] - 1
|
||||||
# Add 1 to the id because since_id and max_id are inclusive
|
elif not hasattr(function, 'iter_key') and len(content) > 0:
|
||||||
if hasattr(function, 'iter_metadata'):
|
params['max_id'] = min(content, key=lambda i: i['id'])['id'] - 1
|
||||||
since_id = content[function.iter_metadata].get('since_id_str')
|
else:
|
||||||
else:
|
raise StopIteration
|
||||||
since_id = content[0]['id_str']
|
elif function.iter_mode == 'cursor':
|
||||||
params['since_id'] = (int(since_id) - 1)
|
params['cursor'] = content['next_cursor_str']
|
||||||
elif function.iter_mode == 'cursor':
|
|
||||||
params['cursor'] = content['next_cursor_str']
|
|
||||||
except (TypeError, ValueError): # pragma: no cover
|
|
||||||
raise TwythonError('Unable to generate next page of search results, `page` is not a number.')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def unicode2utf8(text):
|
def unicode2utf8(text):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue