Add QRZ fallback to DXCC/country/zone lookups

This commit is contained in:
Ian Renton
2025-10-10 06:47:42 +01:00
parent c455e6e1a7
commit 5c3adcdd4d

View File

@@ -47,47 +47,86 @@ def infer_band_from_freq(freq):
# Infer a country name from a callsign
def infer_country_from_callsign(call):
try:
# Get base callsign, assuming this will be the longest of any /-separated sections.
# Use the full callsign, falling back to the base callsign, assuming this will be the longest of any /-separated
# sections.
country = CALL_INFO_BASIC.get_country_name(call)
if not country:
base_call = max(call.split("/"), key=len)
return CALL_INFO_BASIC.get_country_name(base_call)
country = CALL_INFO_BASIC.get_country_name(base_call)
except KeyError as e:
return None
country = None
if not country:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "country" in qrz_data:
country = qrz_data["country"]
return country
# Infer a DXCC ID from a callsign
def infer_dxcc_id_from_callsign(call):
try:
# Get base callsign, assuming this will be the longest of any /-separated sections.
# Start with the basic country-files.com-based decoder. Use the full callsign, falling back to the base
# callsign, assuming this will be the longest of any /-separated sections. Then if that doesn't provide data,
# and we have QRZ data, try the same with that.
dxcc = CALL_INFO_BASIC.get_adif_id(call)
if not dxcc:
base_call = max(call.split("/"), key=len)
return CALL_INFO_BASIC.get_adif_id(base_call)
dxcc = CALL_INFO_BASIC.get_adif_id(base_call)
except KeyError as e:
return None
dxcc = None
if not dxcc:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "adif" in qrz_data:
dxcc = qrz_data["adif"]
return dxcc
# Infer a continent shortcode from a callsign
def infer_continent_from_callsign(call):
try:
# Get base callsign, assuming this will be the longest of any /-separated sections.
# Start with the basic country-files.com-based decoder. Use the full callsign, falling back to the base
# callsign, assuming this will be the longest of any /-separated sections.
continent = CALL_INFO_BASIC.get_continent(call)
if not continent:
base_call = max(call.split("/"), key=len)
return CALL_INFO_BASIC.get_continent(base_call)
continent = CALL_INFO_BASIC.get_continent(base_call)
except KeyError as e:
return None
continent = None
return continent
# Infer a CQ zone from a callsign
def infer_cq_zone_from_callsign(call):
try:
# Get base callsign, assuming this will be the longest of any /-separated sections.
# Start with the basic country-files.com-based decoder. Use the full callsign, falling back to the base
# callsign, assuming this will be the longest of any /-separated sections. Then if that doesn't provide data,
# and we have QRZ data, try the same with that.
cqz = CALL_INFO_BASIC.get_cqz(call)
if not cqz:
base_call = max(call.split("/"), key=len)
return CALL_INFO_BASIC.get_cqz(base_call)
cqz = CALL_INFO_BASIC.get_cqz(base_call)
except KeyError as e:
return None
cqz = None
if not cqz:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "cqz" in qrz_data:
cqz = qrz_data["cqz"]
return cqz
# Infer a ITU zone from a callsign
def infer_itu_zone_from_callsign(call):
try:
# Get base callsign, assuming this will be the longest of any /-separated sections.
# Start with the basic country-files.com-based decoder. Use the full callsign, falling back to the base
# callsign, assuming this will be the longest of any /-separated sections. Then if that doesn't provide data,
# and we have QRZ data, try the same with that.
ituz = CALL_INFO_BASIC.get_ituz(call)
if not ituz:
base_call = max(call.split("/"), key=len)
return CALL_INFO_BASIC.get_ituz(base_call)
ituz = CALL_INFO_BASIC.get_ituz(base_call)
except KeyError as e:
return None
ituz = None
if not ituz:
qrz_data = get_qrz_data_for_callsign(call)
if qrz_data and "ituz" in qrz_data:
ituz = qrz_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
def get_qrz_data_for_callsign(call):