Task 2: adding docstrings and typehints, raise errors

This commit is contained in:
Marco Schmid 2026-04-21 18:21:03 +02:00
parent be9ccefd6a
commit c37790d461

50
main.py
View File

@ -1,8 +1,34 @@
import requests
from pprint import pprint from pprint import pprint
OVERPASS_URL = "https://overpass-api.de/api/interpreter"
BERGBAHN_QUERY = """
[out:json][timeout:3][maxsize:500000];
(
node["aerialway"="station"]({bbox});
way["aerialway"="station"]({bbox});
node["railway"="funicular"]({bbox});
way["railway"="funicular"]({bbox});
node["railway"="station"]["funicular"="yes"]({bbox});
);
out center body;
"""
def fetch_bergbahnen(bbox) -> dict: def fetch_bergbahnen(bbox) -> dict:
return {} bbox_str = ",".join(map(str, bbox))
query = BERGBAHN_QUERY.format(bbox=bbox_str)
resp = requests.post(
OVERPASS_URL,
data={"data": query},
timeout=90,
headers={"User-Agent": "GeoService/1.0 (poi-generator)"},
)
return resp.json()
if __name__ == "__main__": if __name__ == "__main__":
@ -13,20 +39,8 @@ if __name__ == "__main__":
# TASK: # TASK:
# Overpass-Query: -> wir wollen diesen in eine Python-Funktion 'fetch_bergbahnen()' einbauen # * Fügt der aktuellen Funktion einen aussagekräftigen docstrings und typehints hinzu
# * Versucht ein Error-Management mit aufzubauen. Werft einen 'RuntimeError'-Error, wenn etwas in der Funktion
# [out:json][timeout:60]; # nicht klappt.
# ( # -> Was könnte nicht klappen?
# node["aerialway"="station"]({{bbox}}); # * Versucht mal bbox auf (45.8, 5.9, 47.8, 10.5) zu setzen und die Funktion aufzurufen
# way["aerialway"="station"]({{bbox}});
# node["railway"="funicular"]({{bbox}});
# way["railway"="funicular"]({{bbox}});
# node["railway"="station"]["funicular"="yes"]({{bbox}});
# );
# out center body;
# * Kopiert diesen auf `https://overpass-turbo.eu/` und führt ihn mal aus.
# * Spielt mit den Zoomstufen -> bbox
# * Versucht mehr über bbox herauszufinden (z.B. https://wiki.openstreetmap.org/wiki/Overpass_API)
# * Versucht eine einfache fetch_bergbahn() zu bauen, die API lautet "https://overpass-api.de/api/interpreter"
# Nutzt dazu die request-Library in Python, wo ihr post- und get-Requests bauen könnt