Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Performs list detail network requests in sequence
"""
Example program that retrieves sink speed for first 100 meetbouten.
First fetches ids using list endpoint and calls detail endpoint for each id.
p.s. A meetbout is a physical screw on the outside of a building which is used to determine the "sink" rate of the
structure.
"""
import logging
import json
import sys
import requests
import time
N_MEETBOUTEN = 100
log_level = logging.INFO
root = logging.getLogger()
root.setLevel(log_level)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(log_level)
root.addHandler(handler)
log = logging.getLogger(__name__)
def main():
t0 = time.time()
r = requests.get(f'https://api.data.amsterdam.nl/meetbouten/meetbout/?page_size={min(100, N_MEETBOUTEN)}')
data = json.loads(r.content)
meetbouten = data.get('results')
log.debug(f'#meetbouten: {len(meetbouten)}')
ids = [x.get('id') for x in meetbouten[:N_MEETBOUTEN]]
log.debug(f'meetbouten ids: {ids}')
for id in ids:
r = requests.get(f'https://api.data.amsterdam.nl/meetbouten/meetbout/{id}/')
data = json.loads(r.content)
log.info(f'meetbout {id} sink speed {data.get("zakkingssnelheid")}')
difference = time.time() - t0
log.info(f'total script time: {round(difference, 3)}s')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.