Merge pull request #282 from drevicko/cursor-pages
added option to cursor() to yeild "page" - ie: iterators over each page returned by twitter
This commit is contained in:
commit
10e60fca10
1 changed files with 6 additions and 3 deletions
|
|
@ -390,7 +390,7 @@ class Twython(EndpointsMixin, object):
|
||||||
)
|
)
|
||||||
return self.cursor(self.search, q=search_query, **params)
|
return self.cursor(self.search, q=search_query, **params)
|
||||||
|
|
||||||
def cursor(self, function, **params):
|
def cursor(self, function, return_pages=False, **params):
|
||||||
"""Returns a generator for results that match a specified query.
|
"""Returns a generator for results that match a specified query.
|
||||||
|
|
||||||
:param function: Instance of a Twython function (Twython.get_home_timeline, Twython.search)
|
:param function: Instance of a Twython function (Twython.get_home_timeline, Twython.search)
|
||||||
|
|
@ -421,8 +421,11 @@ class Twython(EndpointsMixin, object):
|
||||||
else:
|
else:
|
||||||
results = content
|
results = content
|
||||||
|
|
||||||
for result in results:
|
if return_pages:
|
||||||
yield result
|
yield results
|
||||||
|
else:
|
||||||
|
for result in results:
|
||||||
|
yield result
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue