Commit 51f42da1 authored by Jan Reimes's avatar Jan Reimes
Browse files

refactor(fetch): streamline metadata fetching from whatthespec API

* Update URL for fetching spec metadata.
* Simplify metadata extraction and return structure.
* Ensure versions are always returned as a list.
parent fb03029a
Loading
Loading
Loading
Loading
+18 −13
Original line number Diff line number Diff line
@@ -9,20 +9,25 @@ def fetch_whatthespec_metadata(spec_number: str) -> dict[str, object]:
    """Fetch spec metadata via whatthespec.net JSON API."""
    normalized = normalize_spec_number(spec_number)
    compact = normalized.replace(".", "")
    url = f"https://whatthespec.net/api/specs/{compact}"

    url = f"https://whatthespec.net/3gpp/spec.php?q={compact}&api=1"
    response = requests.get(url, timeout=30)
    response.raise_for_status()
    payload = response.json()
    metadata = {}

    if payload:
        payload = payload[0] if isinstance(payload, list) else payload

        versions = payload.get("versions")
        if not isinstance(versions, list):
            versions = []

    return {
        metadata = {
            "spec_number": normalized,
            "source_name": "whatthespec",
            "source_identifier": payload.get("id"),
            "metadata_payload": payload,
            "versions": versions,
        }

    return metadata
 No newline at end of file