Skip to content

Instantly share code, notes, and snippets.

@qguv
Created July 18, 2022 09:13
Show Gist options
  • Save qguv/5b7b3c962f5093ae8035e91e93816699 to your computer and use it in GitHub Desktop.
Save qguv/5b7b3c962f5093ae8035e91e93816699 to your computer and use it in GitHub Desktop.
Amsterdam crowd density API example
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "74fda5c6",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"base_url = 'https://api.data.amsterdam.nl/v1/crowdmonitor/passanten/'\n",
"json_headers = {'Accept': 'application/hal+json'}"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0babcbdf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'_links': {'schema': 'https://schemas.data.amsterdam.nl/datasets/crowdmonitor/dataset#passanten',\n",
" 'self': {'href': 'https://api.data.amsterdam.nl/v1/crowdmonitor/passanten/107/',\n",
" 'title': 'Kalverstraat t.h.v. 1',\n",
" 'id': 107}},\n",
" 'id': 107,\n",
" 'sensor': 'CMSA-GAKH-01',\n",
" 'periode': 'uur',\n",
" 'naamLocatie': 'Kalverstraat t.h.v. 1',\n",
" 'datumUur': '2021-08-19T07:00:00',\n",
" 'aantalPassanten': 301,\n",
" 'gebied': 'Winkelgebied centrum',\n",
" 'geometrie': {'type': 'Point',\n",
" 'coordinates': [121281.37087987993, 487310.4878591449]}}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = requests.get(base_url + '107', headers=json_headers)\n",
"res.json()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f9ad8d37",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['2021-10-23T13:00:00: 9071',\n",
" '2021-12-18T13:00:00: 9450',\n",
" '2021-12-18T14:00:00: 9573',\n",
" '2022-05-26T13:00:00: 9752',\n",
" '2022-05-26T14:00:00: 9378',\n",
" '2022-05-27T12:00:00: 9112']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"params = {\n",
" 'aantalPassanten[gt]': 9000,\n",
" 'periode': 'uur',\n",
" 'sensor': 'CMSA-GAKH-01',\n",
" '_sort': 'datumUur',\n",
"}\n",
"res = requests.get(base_url, params=params, headers=json_headers)\n",
"[ f'{dp[\"datumUur\"]}: {dp[\"aantalPassanten\"]}' for dp in res.json()['_embedded']['passanten'] ]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment