mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Improve error reporting
This commit is contained in:
+41
-23
@@ -5,7 +5,6 @@ import re
|
||||
import urllib.parse
|
||||
from datetime import timedelta
|
||||
|
||||
import requests
|
||||
import xmltodict
|
||||
from diskcache import Cache
|
||||
from pyhamtools import LookupLib, Callinfo, callinfo
|
||||
@@ -143,12 +142,16 @@ class LookupHelper:
|
||||
try:
|
||||
logging.info("Downloading Country-files.com cty.plist...")
|
||||
response = SEMI_STATIC_URL_DATA_CACHE.get("https://www.country-files.com/cty/cty.plist",
|
||||
headers=HTTP_HEADERS).text
|
||||
headers=HTTP_HEADERS)
|
||||
|
||||
with open(self._country_files_cty_plist_download_location, "w") as f:
|
||||
f.write(response)
|
||||
f.flush()
|
||||
return True
|
||||
if response.ok:
|
||||
with open(self._country_files_cty_plist_download_location, "w") as f:
|
||||
f.write(response.text)
|
||||
f.flush()
|
||||
return True
|
||||
else:
|
||||
logging.warning(f"HTTP {response.status_code} when downloading Country-files.com cty.plist.")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Exception when downloading Clublog cty.xml", e)
|
||||
@@ -161,12 +164,16 @@ class LookupHelper:
|
||||
logging.info("Downloading dxcc.json...")
|
||||
response = SEMI_STATIC_URL_DATA_CACHE.get(
|
||||
"https://raw.githubusercontent.com/k0swe/dxcc-json/refs/heads/main/dxcc.json",
|
||||
headers=HTTP_HEADERS).text
|
||||
headers=HTTP_HEADERS)
|
||||
|
||||
with open(self._dxcc_json_download_location, "w") as f:
|
||||
f.write(response)
|
||||
f.flush()
|
||||
return True
|
||||
if response.ok:
|
||||
with open(self._dxcc_json_download_location, "w") as f:
|
||||
f.write(response.text)
|
||||
f.flush()
|
||||
return True
|
||||
else:
|
||||
logging.warning(f"HTTP {response.status_code} when downloading dxcc.json.")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Exception when downloading dxcc.json", e)
|
||||
@@ -496,14 +503,20 @@ class LookupHelper:
|
||||
|
||||
for lookup_call in calls_to_try:
|
||||
try:
|
||||
lookup_response = requests.get(
|
||||
response = SEMI_STATIC_URL_DATA_CACHE.get(
|
||||
self._qrz_base_url + "?s=" + session_key + "&callsign=" + urllib.parse.quote_plus(lookup_call),
|
||||
headers=HTTP_HEADERS, timeout=10).content
|
||||
raw = xmltodict.parse(lookup_response).get("QRZDatabase", {}).get("Callsign")
|
||||
if raw:
|
||||
data = _normalize_qrz_data(raw)
|
||||
self._qrz_callsign_data_cache.add(call, data, expire=604800) # 1 week in seconds
|
||||
return data
|
||||
headers=HTTP_HEADERS, timeout=10)
|
||||
if response.ok:
|
||||
raw = xmltodict.parse(response.content).get("QRZDatabase", {}).get("Callsign")
|
||||
if raw:
|
||||
data = _normalize_qrz_data(raw)
|
||||
self._qrz_callsign_data_cache.add(call, data, expire=604800) # 1 week in seconds
|
||||
return data
|
||||
elif not response.from_cache:
|
||||
logging.warning("Malformed response looking up callsign %s using QRZ", lookup_call)
|
||||
elif not response.from_cache:
|
||||
logging.warning("HTTP %d looking up callsign %s using QRZ", lookup_call)
|
||||
|
||||
except (KeyError, ValueError):
|
||||
continue
|
||||
except Exception:
|
||||
@@ -552,12 +565,17 @@ class LookupHelper:
|
||||
|
||||
for lookup_call in calls_to_try:
|
||||
try:
|
||||
lookup_data = SEMI_STATIC_URL_DATA_CACHE.get(
|
||||
response = SEMI_STATIC_URL_DATA_CACHE.get(
|
||||
self._hamqth_base_url + "?id=" + session_id + "&callsign=" + urllib.parse.quote_plus(
|
||||
lookup_call) + "&prg=" + HAMQTH_PRG, headers=HTTP_HEADERS).content
|
||||
data = xmltodict.parse(lookup_data)["HamQTH"]["search"]
|
||||
self._hamqth_callsign_data_cache.add(call, data, expire=604800) # 1 week in seconds
|
||||
return data
|
||||
lookup_call) + "&prg=" + HAMQTH_PRG, headers=HTTP_HEADERS)
|
||||
if response.ok:
|
||||
data = xmltodict.parse(response.content)["HamQTH"]["search"]
|
||||
self._hamqth_callsign_data_cache.add(call, data, expire=604800) # 1 week in seconds
|
||||
return data
|
||||
elif not response.from_cache:
|
||||
logging.warning("HTTP %d looking up callsign %s using HamQTH", response.status_code, lookup_call)
|
||||
return None
|
||||
|
||||
except (KeyError, ValueError):
|
||||
continue
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user