Improved lookup for callsigns and display of DXpedition DXCC name on alerts page #38

This commit is contained in:
Ian Renton
2025-10-11 21:34:44 +01:00
parent 7cf6d05c4b
commit ba84b90315
4 changed files with 51 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ from pyhamtools.frequency import freq_to_band
from pyhamtools.locator import latlong_to_locator
from core.config import config
from core.constants import BANDS, UNKNOWN_BAND, CW_MODES, PHONE_MODES, DATA_MODES, ALL_MODES
from core.constants import BANDS, UNKNOWN_BAND, CW_MODES, PHONE_MODES, DATA_MODES, ALL_MODES, QRZCQ_CALLSIGN_LOOKUP_DATA
# Lookup helpers from pyhamtools
LOOKUP_LIB_BASIC = LookupLib(lookuptype="countryfile")
@@ -55,10 +55,16 @@ def infer_country_from_callsign(call):
country = CALL_INFO_BASIC.get_country_name(base_call)
except KeyError as e:
country = None
# Couldn't get anything from basic call info database, try QRZ.com
if not country:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "country" in qrz_data:
country = qrz_data["country"]
# Couldn't get anything from QRZ.com database, try QRZCQ data
if not country:
qrzcq_data = get_qrzcq_data_for_callsign(call)
if qrzcq_data and qrzcq_data["country"]:
country = qrzcq_data["country"]
return country
# Infer a DXCC ID from a callsign
@@ -73,10 +79,16 @@ def infer_dxcc_id_from_callsign(call):
dxcc = CALL_INFO_BASIC.get_adif_id(base_call)
except KeyError as e:
dxcc = None
# Couldn't get anything from basic call info database, try QRZ.com
if not dxcc:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "adif" in qrz_data:
dxcc = qrz_data["adif"]
# Couldn't get anything from QRZ.com database, try QRZCQ data
if not dxcc:
qrzcq_data = get_qrzcq_data_for_callsign(call)
if qrzcq_data and qrzcq_data["dxcc"]:
dxcc = qrzcq_data["dxcc"]
return dxcc
# Infer a continent shortcode from a callsign
@@ -90,6 +102,11 @@ def infer_continent_from_callsign(call):
continent = CALL_INFO_BASIC.get_continent(base_call)
except KeyError as e:
continent = None
# Couldn't get anything from basic call info database, try QRZCQ data
if not continent:
qrzcq_data = get_qrzcq_data_for_callsign(call)
if qrzcq_data and qrzcq_data["continent"]:
continent = qrzcq_data["continent"]
return continent
# Infer a CQ zone from a callsign
@@ -104,10 +121,16 @@ def infer_cq_zone_from_callsign(call):
cqz = CALL_INFO_BASIC.get_cqz(base_call)
except KeyError as e:
cqz = None
# Couldn't get anything from basic call info database, try QRZ.com
if not cqz:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "cqz" in qrz_data:
cqz = qrz_data["cqz"]
# Couldn't get anything from QRZ.com database, try QRZCQ data
if not cqz:
qrzcq_data = get_qrzcq_data_for_callsign(call)
if qrzcq_data and qrzcq_data["cqz"]:
cqz = qrzcq_data["cqz"]
return cqz
# Infer a ITU zone from a callsign
@@ -122,10 +145,16 @@ def infer_itu_zone_from_callsign(call):
ituz = CALL_INFO_BASIC.get_ituz(base_call)
except KeyError as e:
ituz = None
# Couldn't get anything from basic call info database, try QRZ.com
if not ituz:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "ituz" in qrz_data:
ituz = qrz_data["ituz"]
# Couldn't get anything from QRZ.com database, try QRZCQ data
if not ituz:
qrzcq_data = get_qrzcq_data_for_callsign(call)
if qrzcq_data and qrzcq_data["ituz"]:
ituz = qrzcq_data["ituz"]
return ituz
# Utility method to get QRZ.com data from cache if possible, if not get it from the API and cache it
@@ -145,6 +174,15 @@ def get_qrz_data_for_callsign(call):
else:
return None
# Utility method to get QRZCQ data from our constants table, if we can find it
def get_qrzcq_data_for_callsign(call):
# Iterate in reverse order - see comments on the data structure itself
for entry in reversed(QRZCQ_CALLSIGN_LOOKUP_DATA):
if call.startswith(entry["prefix"]):
print(call + " " + str(entry))
return entry
return None
# Infer an operator name from a callsign (requires QRZ.com)
def infer_name_from_callsign(call):
data = get_qrz_data_for_callsign(call)