Created
August 20, 2025 21:51
-
-
Save elyssonmr/d41e19e22bb19dd78ad6bc8dbd2ec7f0 to your computer and use it in GitHub Desktop.
Gist simulating a generator to process data from a API
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
| import requests | |
| def retrieve_data(max): | |
| counter = 0 | |
| while counter < max: | |
| data = {'data': list(range(1, 300))} | |
| print('Requesting the api') | |
| response = requests.post('https://httpbin.org/anything', json=data) | |
| if response.ok: | |
| yield response.json()['json'] | |
| counter += 1 | |
| print(type(retrieve_data)) | |
| for json_data in retrieve_data(5): | |
| for number in json_data['data']: | |
| print(number, end=" ") | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment