Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2019 16:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
import logging
import json
import sys
import requests
import time
log_level = logging.INFO
root = logging.getLogger()
handler = logging.StreamHandler(sys.stdout)
log = logging.getLogger(__name__)
def main():
t0 = time.time()
r = requests.get(f'{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'{id}/')
data = json.loads(r.content)'meetbout {id} sink speed {data.get("zakkingssnelheid")}')
difference = time.time() - t0'total script time: {round(difference, 3)}s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment