overpass_old/main.py

46 lines
1.2 KiB
Python

import requests
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:
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__":
bbox = (46.72, 9.70, 46.92, 10.00)
result = fetch_bergbahnen(bbox)
pprint(result)
# TASK:
# * 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
# nicht klappt.
# -> Was könnte nicht klappen?
# * Versucht mal bbox auf (45.8, 5.9, 47.8, 10.5) zu setzen und die Funktion aufzurufen