how to get timestamp_measured and concentration values from the api https://api.luchtmeetnet.nl in python

To retrieve the data from the API in Python, you can use the requests library. Here is an example code snippet that retrieves the data for a specific measurement station:

main.py
import requests
import json

# specify the measurement station id and the start and end dates
station_id = "NL41008"
start_date = "2022-01-01T00:00:00"
end_date = "2022-01-01T01:00:00"

# make the API request
url = f"https://api.luchtmeetnet.nl/open_api/measurements?station_id={station_id}&start={start_date}&end={end_date}"
response = requests.get(url)
data = json.loads(response.text)

# extract the timestamp_measured and concentration values from the API response
measurements = data["data"]["items"]
timestamp_measured = [m["timestamp_measured"] for m in measurements]
concentrations = [m["concentration"] for m in measurements]
635 chars
18 lines

In this example, we specify the measurement station id, the start and end dates, and use them to construct the API request URL. We then make the API request using requests.get() and parse the API response using json.loads(). Finally, we extract the timestamp_measured and concentration values from the API response by iterating over the measurements list and appending these values to separate lists.

Note that the API response contains additional data such as measurement units and averaging periods, which you can also extract if needed.

related categories

gistlibby LogSnag