37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def store_to_disk(
|
|
results: list[dict],
|
|
poi_type: str = "overpass",
|
|
output_dir: Path = Path("."),
|
|
) -> Path:
|
|
"""
|
|
Speichert eine Liste von OSM-Elementen als JSON-Datei auf der Festplatte.
|
|
|
|
Der Dateiname wird aus dem poi_type-Parameter abgeleitet:
|
|
z.B. poi_type="bergbahn" → "bergbahn_results.json"
|
|
|
|
Args:
|
|
results (list[dict]): Liste von OSM-Elementen, wie sie die
|
|
Overpass API unter "elements" zurückgibt.
|
|
poi_type (str): Bezeichnung des POI-Typs. Bestimmt den
|
|
Dateinamen. Standard: "overpass"
|
|
output_dir (Path): Zielverzeichnis. Wird erstellt falls nicht
|
|
vorhanden. Standard: aktuelles Verzeichnis.
|
|
|
|
Returns:
|
|
Path: Absoluter Pfad zur gespeicherten Datei.
|
|
|
|
Raises:
|
|
OSError: Wenn das Verzeichnis nicht erstellt oder die Datei nicht
|
|
geschrieben werden kann (z.B. fehlende Schreibrechte).
|
|
"""
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
output_path = output_dir / f"{poi_type}_results.json"
|
|
|
|
with output_path.open("w", encoding="utf-8") as f:
|
|
json.dump(results, f, indent=2, ensure_ascii=False)
|
|
|
|
return output_path.resolve() |