Initial Vibe coded project

This commit is contained in:
Olaf committed 2026-10-20 14:18:35 +02:00
commit 0891cf12a5
21 files changed
+2830

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import json
from typing import Any
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
USER_AGENT = "FlightMap/0.1 (local non-commercial flight mapping)"
def request_json(
url: str, *, data: bytes | None = None, headers: dict[str, str] | None = None
) -> Any:
request = Request(url, data=data, headers={"User-Agent": USER_AGENT, **(headers or {})})
try:
with urlopen(request, timeout=60) as response:
return json.load(response)
except HTTPError as exc:
retry = exc.headers.get("Retry-After")
suffix = f"; retry after {retry}" if retry else ""
raise RuntimeError(f"Remote service returned HTTP {exc.code}{suffix}.") from exc
except (URLError, TimeoutError) as exc:
raise RuntimeError(
f"Remote service connection failed: {exc.reason if isinstance(exc, URLError) else exc}"
) from exc
except (ValueError, UnicodeError) as exc:
raise RuntimeError("Remote service returned invalid JSON.") from exc