Created
April 9, 2013 09:47
-
-
Save cklein/5344480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def json_iterator(url, method='GET', content=None, credentials=None, datanodename='data'): | |
""" | |
Rufe JSON-Daten ab. | |
Es wird die seitenweise Darstellung von gaetk.BasicHandler.paginate unterstützt. | |
""" | |
if content is None: | |
content = {} | |
while True: | |
try: | |
response = huTools.http.fetch_json2xx(url, | |
method=method, | |
content=content, | |
credentials=credentials) | |
except huTools.http.exceptions.WrongStatusCode: | |
break | |
for element in response[datanodename]: | |
yield element | |
if not response['more_objects']: | |
break | |
else: | |
cursor_information = response.get('next_qs', '') | |
tmp = cgi.parse_qs(cursor_information) | |
for key, values in tmp.items(): | |
content[key] = values[0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment