199 lines
5.2 KiB
Plaintext
199 lines
5.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "49d54764",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import requests\n",
|
|
"import json\n",
|
|
"import time\n",
|
|
"\n",
|
|
"API_URL = \"https://verkehr.autobahn.de/o/autobahn/\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "76963637",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Alle Straßennamen erhalten"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8638c916",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"response = requests.get(API_URL)\n",
|
|
"\n",
|
|
"with open(\"data/autobahn.json\", mode=\"w+\", encoding=\"utf8\") as autobahn_file:\n",
|
|
" roads = json.loads(response.text)\n",
|
|
" autobahn_file.write(json.dumps(roads))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b67e0048",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Alle Baustellen erhalten"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "74e428ce",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"total_roadworks = {}\n",
|
|
"\n",
|
|
"for i, road in enumerate(roads[\"roads\"]):\n",
|
|
" response = requests.get(f\"{API_URL}/{road}/services/roadworks\")\n",
|
|
" roadworks = json.loads(response.text)\n",
|
|
" total_roadworks[road] = roadworks\n",
|
|
" print(f\"{i}/{len(roads[\"roads\"])} Autobahnen\")\n",
|
|
" time.sleep(5)\n",
|
|
"\n",
|
|
"with open(\"data/roadworks.json\", mode=\"w+\", encoding=\"utf8\") as roadwork_file:\n",
|
|
" roadwork_file.write(json.dumps(total_roadworks))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5462f028",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"roads[\"roads\"][88]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7ea3d8bc",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Alle Rastplätze erhalten"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "eecd5da0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"total_parking_lorries = {}\n",
|
|
"\n",
|
|
"for i, road in enumerate(roads[\"roads\"]):\n",
|
|
" response = requests.get(f\"{API_URL}/{road}/services/parking_lorry\")\n",
|
|
" if response.status_code != 200:\n",
|
|
" continue\n",
|
|
" try:\n",
|
|
" parking_lorry = json.loads(response.text)\n",
|
|
" total_parking_lorries[road] = parking_lorry\n",
|
|
" print(f\"{i}/{len(roads[\"roads\"])} Autobahnen\")\n",
|
|
" except json.JSONDecodeError as e:\n",
|
|
" print(f\"{i} Error {str(e)} occured\")\n",
|
|
" time.sleep(3)\n",
|
|
"\n",
|
|
"with open(\"data/parkinglorries.json\", mode=\"w+\", encoding=\"utf8\") as parkinglorries_file:\n",
|
|
" parkinglorries_file.write(json.dumps(total_parking_lorries))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ff2efc9f",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Alle Ladestationen erhalten"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4a34ff23",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"total_charging_stations = {}\n",
|
|
"\n",
|
|
"for i, road in enumerate(roads[\"roads\"]):\n",
|
|
" response = requests.get(f\"{API_URL}/{road}/services/electric_charging_station\")\n",
|
|
" if response.status_code != 200:\n",
|
|
" continue\n",
|
|
" try:\n",
|
|
" charging_station = json.loads(response.text)\n",
|
|
" total_charging_stations[road] = charging_station\n",
|
|
" print(f\"{i}/{len(roads[\"roads\"])} Autobahnen\")\n",
|
|
" except json.JSONDecodeError as e:\n",
|
|
" print(f\"{i} Error {str(e)} occured\")\n",
|
|
" time.sleep(3)\n",
|
|
"\n",
|
|
"with open(\"data/chargingstations.json\", mode=\"w+\", encoding=\"utf8\") as chargingstations_file:\n",
|
|
" chargingstations_file.write(json.dumps(total_charging_stations))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6db81957",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Alle Webcams"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "224db1fa",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"total_webcams = {}\n",
|
|
"\n",
|
|
"for i, road in enumerate(roads[\"roads\"]):\n",
|
|
" response = requests.get(f\"{API_URL}/{road}/services/webcam\")\n",
|
|
" if response.status_code != 200:\n",
|
|
" continue\n",
|
|
" try:\n",
|
|
" webcam = json.loads(response.text)\n",
|
|
" total_webcams[road] = webcam\n",
|
|
" print(f\"{i}/{len(roads[\"roads\"])} Autobahnen\")\n",
|
|
" except json.JSONDecodeError as e:\n",
|
|
" print(f\"{i} Error {str(e)} occured\")\n",
|
|
" time.sleep(3)\n",
|
|
"\n",
|
|
"with open(\"data/webcams.json\", mode=\"w+\", encoding=\"utf8\") as webcam_file:\n",
|
|
" webcam_file.write(json.dumps(total_webcams))"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "venv (3.14.4)",
|
|
"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.14.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|