diff --git a/core/sig_utils.py b/core/sig_utils.py index fc9469e..aacd246 100644 --- a/core/sig_utils.py +++ b/core/sig_utils.py @@ -29,7 +29,10 @@ def populate_sig_ref_info(sig_ref): ref_id = sig_ref.id try: if sig.upper() == "POTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://api.pota.app/park/" + ref_id, headers=HTTP_HEADERS).json() + response = SEMI_STATIC_URL_DATA_CACHE.get("https://api.pota.app/park/" + ref_id, headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None if data: fullname = str(data["name"]) if "name" in data else None if fullname and "parktypeDesc" in data and data["parktypeDesc"] != "": @@ -40,8 +43,11 @@ def populate_sig_ref_info(sig_ref): sig_ref.latitude = data["latitude"] if "latitude" in data else None sig_ref.longitude = data["longitude"] if "longitude" in data else None elif sig.upper() == "SOTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://api-db2.sota.org.uk/api/summits/" + ref_id, - headers=HTTP_HEADERS).json() + response = SEMI_STATIC_URL_DATA_CACHE.get("https://api-db2.sota.org.uk/api/summits/" + ref_id, + headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None if data: sig_ref.name = data["name"] if "name" in data else None sig_ref.url = "https://www.sotadata.org.uk/en/summit/" + ref_id @@ -50,8 +56,11 @@ def populate_sig_ref_info(sig_ref): sig_ref.longitude = data["longitude"] if "longitude" in data else None sig_ref.activation_score = data["points"] if "points" in data else None elif sig.upper() == "WWBOTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://api.wwbota.org/bunkers/" + ref_id, - headers=HTTP_HEADERS).json() + response = SEMI_STATIC_URL_DATA_CACHE.get("https://api.wwbota.org/bunkers/" + ref_id, + headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None if data: sig_ref.name = data["name"] if "name" in data else None sig_ref.url = "https://bunkerwiki.org/?s=" + ref_id if ref_id.startswith("B/G") else None @@ -59,8 +68,11 @@ def populate_sig_ref_info(sig_ref): sig_ref.latitude = data["lat"] if "lat" in data else None sig_ref.longitude = data["long"] if "long" in data else None elif sig.upper() == "GMA" or sig.upper() == "ARLHS" or sig.upper() == "ILLW" or sig.upper() == "WCA" or sig.upper() == "MOTA" or sig.upper() == "IOTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://www.cqgma.org/api/ref/?" + ref_id, - headers=HTTP_HEADERS).json() + response = SEMI_STATIC_URL_DATA_CACHE.get("https://www.cqgma.org/api/ref/?" + ref_id, + headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None if data: sig_ref.name = data["name"] if "name" in data else None sig_ref.url = "https://www.cqgma.org/zinfo.php?ref=" + ref_id @@ -68,9 +80,12 @@ def populate_sig_ref_info(sig_ref): sig_ref.latitude = data["latitude"] if "latitude" in data else None sig_ref.longitude = data["longitude"] if "longitude" in data else None elif sig.upper() == "WWFF": - wwff_csv_data = SEMI_STATIC_URL_DATA_CACHE.get("https://wwff.co/wwff-data/wwff_directory.csv", + wwff_response = SEMI_STATIC_URL_DATA_CACHE.get("https://wwff.co/wwff-data/wwff_directory.csv", headers=HTTP_HEADERS) - wwff_index = {row["reference"]: row for row in csv.DictReader(wwff_csv_data.content.decode().splitlines())} + if not wwff_response.ok: + logging.warning("HTTP %d looking up %s ref %s", wwff_response.status_code, sig, ref_id) + return sig_ref + wwff_index = {row["reference"]: row for row in csv.DictReader(wwff_response.content.decode().splitlines())} row = wwff_index.get(ref_id) if row: sig_ref.name = row["name"] if "name" in row else None @@ -79,10 +94,13 @@ def populate_sig_ref_info(sig_ref): sig_ref.latitude = float(row["latitude"]) if "latitude" in row and row["latitude"] != "-" else None sig_ref.longitude = float(row["longitude"]) if "longitude" in row and row["longitude"] != "-" else None elif sig.upper() == "SIOTA": - siota_csv_data = SEMI_STATIC_URL_DATA_CACHE.get("https://www.silosontheair.com/data/silos.csv", + siota_response = SEMI_STATIC_URL_DATA_CACHE.get("https://www.silosontheair.com/data/silos.csv", headers=HTTP_HEADERS) + if not siota_response.ok: + logging.warning("HTTP %d looking up %s ref %s", siota_response.status_code, sig, ref_id) + return sig_ref siota_index = {row["SILO_CODE"]: row for row in - csv.DictReader(siota_csv_data.content.decode().splitlines())} + csv.DictReader(siota_response.content.decode().splitlines())} row = siota_index.get(ref_id) if row: sig_ref.name = row["NAME"] if "NAME" in row else None @@ -90,10 +108,13 @@ def populate_sig_ref_info(sig_ref): sig_ref.latitude = float(row["LAT"]) if "LAT" in row else None sig_ref.longitude = float(row["LNG"]) if "LNG" in row else None elif sig.upper() == "WOTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://www.wota.org.uk/mapping/data/summits.json", - headers=HTTP_HEADERS).json() + response = SEMI_STATIC_URL_DATA_CACHE.get("https://www.wota.org.uk/mapping/data/summits.json", + headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None if data: - for feature in data["features"]: + for feature in data.get("features", []): if feature["properties"]["wotaId"] == ref_id: sig_ref.name = feature["properties"]["title"] # Fudge WOTA URLs. Outlying fell (LDO) URLs don't match their ID numbers but require 214 to be @@ -107,8 +128,11 @@ def populate_sig_ref_info(sig_ref): sig_ref.longitude = feature["geometry"]["coordinates"][0] break elif sig.upper() == "ZLOTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://ontheair.nz/assets/assets.json", headers=HTTP_HEADERS).json() - if data: + response = SEMI_STATIC_URL_DATA_CACHE.get("https://ontheair.nz/assets/assets.json", headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None + if isinstance(data, list): for asset in data: if asset["code"] == ref_id: sig_ref.name = asset["name"] @@ -125,9 +149,12 @@ def populate_sig_ref_info(sig_ref): sig_ref.name = sig_ref.id sig_ref.url = "https://www.beachesontheair.com/beaches/" + sig_ref.name.lower().replace(" ", "-") elif sig.upper() == "LLOTA": - data = SEMI_STATIC_URL_DATA_CACHE.get("https://llota.app/api/public/references", - headers=HTTP_HEADERS).json() - if data: + response = SEMI_STATIC_URL_DATA_CACHE.get("https://llota.app/api/public/references", + headers=HTTP_HEADERS) + if not response.ok: + logging.warning("HTTP %d looking up %s ref %s", response.status_code, sig, ref_id) + data = response.json() if response.ok else None + if isinstance(data, list): for ref in data: if ref["reference_code"] == ref_id: sig_ref.name = str(ref["name"]) diff --git a/templates/add_spot.html b/templates/add_spot.html index c1b0238..36992f7 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -76,7 +76,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index 4dfa4fe..9a240b9 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -75,7 +75,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index 81ca9ab..21c6af2 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -77,8 +77,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 4e2aeea..b6cbc90 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -10,10 +10,10 @@ - - - - + + + + {% end %} {% block body %}