mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Add QRZ fallback to DXCC/country/zone lookups
This commit is contained in:
@@ -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.
|
||||
base_call = max(call.split("/"), key=len)
|
||||
return CALL_INFO_BASIC.get_country_name(base_call)
|
||||
# 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)
|
||||
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.
|
||||
base_call = max(call.split("/"), key=len)
|
||||
return CALL_INFO_BASIC.get_adif_id(base_call)
|
||||
# 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)
|
||||
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.
|
||||
base_call = max(call.split("/"), key=len)
|
||||
return CALL_INFO_BASIC.get_continent(base_call)
|
||||
# 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)
|
||||
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.
|
||||
base_call = max(call.split("/"), key=len)
|
||||
return CALL_INFO_BASIC.get_cqz(base_call)
|
||||
# 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)
|
||||
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.
|
||||
base_call = max(call.split("/"), key=len)
|
||||
return CALL_INFO_BASIC.get_ituz(base_call)
|
||||
# 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)
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user