Skip to content

Instantly share code, notes, and snippets.

@FlippAre
Created December 22, 2017 14:23
Show Gist options
  • Select an option

  • Save FlippAre/0f541bd7a8583fabb2acbab3abab860f to your computer and use it in GitHub Desktop.

Select an option

Save FlippAre/0f541bd7a8583fabb2acbab3abab860f to your computer and use it in GitHub Desktop.
Recusive get
def _get_data(self, url: str, name_of_data_node: str) -> dict:
"""
Helper function to fetch data from admin and take care of pageing
Parameters
----------
:param url: API endpoint address
:param name_of_data_node: Name of the key where the requested data is stored
Returns
-------
:return A list of the data requested
"""
r = requests.get(url)
if r.ok:
r_json = r.json()
data = r_json[name_of_data_node]
if r_json["next"]: # The data is paged. Request next page
return data + self._get_data(r_json["next"], name_of_data_node)
else:
return data
else:
logging.error("Lime GO answered with an error! %s", r.status_code)
r.raise_for_status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment