From 0fa8b44c9c5a7d269f2749a570afa0256606b372 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sat, 29 Nov 2025 15:04:19 +0000 Subject: [PATCH] Defensive coding --- spotproviders/gma.py | 70 +++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/spotproviders/gma.py b/spotproviders/gma.py index 85b752e..e106775 100644 --- a/spotproviders/gma.py +++ b/spotproviders/gma.py @@ -41,40 +41,42 @@ class GMA(HTTPSpotProvider): dx_longitude=float(source_spot["LON"]) if (source_spot["LON"] and source_spot["LON"] != "") else None) # GMA doesn't give what programme (SIG) the reference is for until we separately look it up. - ref_response = SEMI_STATIC_URL_DATA_CACHE.get(self.REF_INFO_URL_ROOT + source_spot["REF"], - headers=HTTP_HEADERS) - # Sometimes this is blank, so handle that - if ref_response.text is not None and ref_response.text != "": - ref_info = ref_response.json() - # If this is POTA, SOTA or WWFF data we already have it through other means, so ignore. POTA and WWFF - # spots come through with reftype=POTA or reftype=WWFF. SOTA is harder to figure out because both SOTA - # and GMA summits come through with reftype=Summit, so we must check for the presence of a "sota" entry - # to determine if it's a SOTA summit. - if "reftype" in ref_info and ref_info["reftype"] not in ["POTA", "WWFF"] and (ref_info["reftype"] != "Summit" or ref_info["sota"] == ""): - match ref_info["reftype"]: - case "Summit": - spot.sig_refs[0].sig = "GMA" - spot.sig = "GMA" - case "IOTA Island": - spot.sig_refs[0].sig = "IOTA" - spot.sig = "IOTA" - case "Lighthouse (ILLW)": - spot.sig_refs[0].sig = "ILLW" - spot.sig = "ILLW" - case "Lighthouse (ARLHS)": - spot.sig_refs[0].sig = "ARLHS" - spot.sig = "ARLHS" - case "Castle": - spot.sig_refs[0].sig = "WCA" - spot.sig = "WCA" - case "Mill": - spot.sig_refs[0].sig = "MOTA" - spot.sig = "MOTA" - case _: - logging.warn("GMA spot found with ref type " + ref_info[ - "reftype"] + ", developer needs to add support for this!") - spot.sig_refs[0].sig = ref_info["reftype"] - spot.sig = ref_info["reftype"] + if "REF" in source_spot: + ref_response = SEMI_STATIC_URL_DATA_CACHE.get(self.REF_INFO_URL_ROOT + source_spot["REF"], + headers=HTTP_HEADERS) + # Sometimes this is blank, so handle that + if ref_response.text is not None and ref_response.text != "": + ref_info = ref_response.json() + # If this is POTA, SOTA or WWFF data we already have it through other means, so ignore. POTA and WWFF + # spots come through with reftype=POTA or reftype=WWFF. SOTA is harder to figure out because both SOTA + # and GMA summits come through with reftype=Summit, so we must check for the presence of a "sota" entry + # to determine if it's a SOTA summit. + if "reftype" in ref_info and ref_info["reftype"] not in ["POTA", "WWFF"] and ( + ref_info["reftype"] != "Summit" or ref_info["sota"] == ""): + match ref_info["reftype"]: + case "Summit": + spot.sig_refs[0].sig = "GMA" + spot.sig = "GMA" + case "IOTA Island": + spot.sig_refs[0].sig = "IOTA" + spot.sig = "IOTA" + case "Lighthouse (ILLW)": + spot.sig_refs[0].sig = "ILLW" + spot.sig = "ILLW" + case "Lighthouse (ARLHS)": + spot.sig_refs[0].sig = "ARLHS" + spot.sig = "ARLHS" + case "Castle": + spot.sig_refs[0].sig = "WCA" + spot.sig = "WCA" + case "Mill": + spot.sig_refs[0].sig = "MOTA" + spot.sig = "MOTA" + case _: + logging.warn("GMA spot found with ref type " + ref_info[ + "reftype"] + ", developer needs to add support for this!") + spot.sig_refs[0].sig = ref_info["reftype"] + spot.sig = ref_info["reftype"] # Add to our list. Don't worry about de-duping, removing old spots etc. at this point; other code will do # that for us.