Created
December 22, 2017 14:23
-
-
Save FlippAre/0f541bd7a8583fabb2acbab3abab860f to your computer and use it in GitHub Desktop.
Recusive get
This file contains hidden or 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 _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