Refactor of caching & data storage part 10 #118

This commit is contained in:
Ian Renton
2026-08-02 10:31:31 +01:00
parent 2157bf114e
commit 11a236e668
15 changed files with 452 additions and 170 deletions
+48
View File
@@ -0,0 +1,48 @@
import logging
from pyhamtools import LookupLib, Callinfo
from data.callsign import Callsign
from providers.callsigndata.file_download_callsign_data_provider import FileDownloadCallsignDataProvider
class CountryFiles(FileDownloadCallsignDataProvider):
"""Callsign data provider for Country-files.com, which provides basic callsign to DXCC entity mapping."""
POLL_INTERVAL_DAYS = 30
DATA_URL = "https://www.country-files.com/cty/cty.plist"
CACHE_PATH = "cache/cty.plist"
_callinfo = None
def __init__(self, provider_config):
super().__init__("CountryFiles.com", provider_config, self.DATA_URL, self.CACHE_PATH, self.POLL_INTERVAL_DAYS)
def _handle_file(self, path):
try:
lookuplib = LookupLib(lookuptype="countryfile", filename=path)
self._callinfo = Callinfo(lookuplib)
return True
except Exception as e:
logging.error("Exception when loading Country Files cty.plist.", e, exc_info=True)
return False
def lookup(self, callsign, lookup_credentials):
# Lookup credentials are not required for this source.
# Lat/lon will only be centre of country or capital city from this source
ll = self._callinfo.get_lat_long(callsign)
lat = None
lon = None
if ll and "latitude" in ll and "longitude" in ll:
lat = float(ll["latitude"])
lon = float(ll["longitude"])
return Callsign(call=callsign,
home_call=self._callinfo.get_homecall(callsign),
country=self._callinfo.get_country_name(callsign),
dxcc_id=self._callinfo.get_adif_id(callsign),
continent=self._callinfo.get_continent(callsign),
cq_zone=self._callinfo.get_cqz(callsign),
itu_zone=self._callinfo.get_ituz(callsign),
latitude=lat,
longitude=lon)