Files
spothole/core/utils.py
2025-09-26 22:37:17 +01:00

58 lines
1.6 KiB
Python

from core.constants import BANDS, UNKNOWN_BAND
from pyhamtools import LookupLib, Callinfo
# Static lookup helpers from pyhamtools
# todo in future add QRZ as a second lookup option in case it provides more data?
lookuplib = LookupLib(lookuptype="countryfile")
callinfo = Callinfo(lookuplib)
# Infer a "mode family" from a mode.
def infer_mode_family_from_mode(mode):
if mode.upper() == "CW":
return "CW"
elif mode.upper() in ["PHONE", "SSB", "USB", "LSB", "AM", "FM", "DMR", "DSTAR", "C4FM", "M17"]:
return "PHONE"
else:
return "DIGI"
# Infer a band from a frequency in kHz
def infer_band_from_freq(freq):
for b in BANDS:
if b.start_freq <= freq <= b.end_freq:
return b
return UNKNOWN_BAND
# Infer a country name from a callsign
def infer_country_from_callsign(call):
try:
return callinfo.get_country_name(call)
except KeyError as e:
return None
# Infer a DXCC ID from a callsign
def infer_dxcc_id_from_callsign(call):
try:
return callinfo.get_adif_id(call)
except KeyError as e:
return None
# Infer a continent shortcode from a callsign
def infer_continent_from_callsign(call):
try:
return callinfo.get_continent(call)
except KeyError as e:
return None
# Infer a CQ zone from a callsign
def infer_cq_zone_from_callsign(call):
try:
return callinfo.get_cqz(call)
except KeyError as e:
return None
# Infer a ITU zone from a callsign
def infer_itu_zone_from_callsign(call):
try:
return callinfo.get_ituz(call)
except KeyError as e:
return None