mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-12-16 00:53:39 +00:00
Exception handling #74
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import csv
|
import csv
|
||||||
|
import logging
|
||||||
|
|
||||||
from pyhamtools.locator import latlong_to_locator
|
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.
|
# Note there is currently no support for KRMNPA location lookup, see issue #61.
|
||||||
def get_sig_ref_info(sig, sig_ref_id):
|
def get_sig_ref_info(sig, sig_ref_id):
|
||||||
sig_ref = SIGRef(id=sig_ref_id, sig=sig)
|
sig_ref = SIGRef(id=sig_ref_id, sig=sig)
|
||||||
|
try:
|
||||||
if sig.upper() == "POTA":
|
if sig.upper() == "POTA":
|
||||||
data = SEMI_STATIC_URL_DATA_CACHE.get("https://api.pota.app/park/" + sig_ref_id, headers=HTTP_HEADERS).json()
|
data = SEMI_STATIC_URL_DATA_CACHE.get("https://api.pota.app/park/" + sig_ref_id, headers=HTTP_HEADERS).json()
|
||||||
if data:
|
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.latitude = data["latitude"] if "latitude" in data else None
|
||||||
sig_ref.longitude = data["longitude"] if "longitude" in data else None
|
sig_ref.longitude = data["longitude"] if "longitude" in data else None
|
||||||
elif sig.upper() == "SOTA":
|
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,
|
data = SEMI_STATIC_URL_DATA_CACHE.get("https://api-db2.sota.org.uk/api/summits/" + sig_ref_id,
|
||||||
headers=HTTP_HEADERS).json()
|
headers=HTTP_HEADERS).json()
|
||||||
if data:
|
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.grid = latlong_to_locator(ll[0], ll[1], 6)
|
||||||
sig_ref.latitude = ll[0]
|
sig_ref.latitude = ll[0]
|
||||||
sig_ref.longitude = ll[1]
|
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
|
return sig_ref
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user