Skip to content

Instantly share code, notes, and snippets.

@elyssonmr
Created August 20, 2025 21:51
Show Gist options
  • Save elyssonmr/d41e19e22bb19dd78ad6bc8dbd2ec7f0 to your computer and use it in GitHub Desktop.
Save elyssonmr/d41e19e22bb19dd78ad6bc8dbd2ec7f0 to your computer and use it in GitHub Desktop.
Gist simulating a generator to process data from a API
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