Skip to content

Instantly share code, notes, and snippets.

@cklein
Created April 9, 2013 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cklein/5344480 to your computer and use it in GitHub Desktop.
Save cklein/5344480 to your computer and use it in GitHub Desktop.
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