Exception handling #74

This commit is contained in:
Ian Renton
2025-11-02 17:59:37 +00:00
parent e83ddead62
commit ebf07f352f

View File

@@ -1,4 +1,5 @@
import csv
import logging
from pyhamtools.locator import latlong_to_locator
@@ -28,6 +29,7 @@ def get_ref_regex_for_sig(sig):
# Note there is currently no support for KRMNPA location lookup, see issue #61.
def get_sig_ref_info(sig, sig_ref_id):
sig_ref = SIGRef(id=sig_ref_id, sig=sig)
try:
if sig.upper() == "POTA":
data = SEMI_STATIC_URL_DATA_CACHE.get("https://api.pota.app/park/" + sig_ref_id, headers=HTTP_HEADERS).json()
if data:
@@ -40,6 +42,7 @@ def get_sig_ref_info(sig, sig_ref_id):
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":
print(sig_ref_id)
data = SEMI_STATIC_URL_DATA_CACHE.get("https://api-db2.sota.org.uk/api/summits/" + sig_ref_id,
headers=HTTP_HEADERS).json()
if data:
@@ -110,7 +113,8 @@ def get_sig_ref_info(sig, sig_ref_id):
sig_ref.grid = latlong_to_locator(ll[0], ll[1], 6)
sig_ref.latitude = ll[0]
sig_ref.longitude = ll[1]
except:
logging.warn("Failed to look up sig_ref info for SIG " + sig + " ref " + sig_ref_id + ".")
return sig_ref