From 9d2b2a1f6670c0933774ff98170cf7864570c414 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Mon, 13 Oct 2025 19:54:20 +0100 Subject: [PATCH] Download country-files.com cty.plist separately so we can cache the result and handle exceptions --- core/constants.py | 1 + core/utils.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/constants.py b/core/constants.py index e120a1c..c45936a 100644 --- a/core/constants.py +++ b/core/constants.py @@ -1,3 +1,4 @@ +from core.config import SERVER_OWNER_CALLSIGN from data.band import Band # General software diff --git a/core/utils.py b/core/utils.py index 42d16a1..c3a9ac2 100644 --- a/core/utils.py +++ b/core/utils.py @@ -20,10 +20,10 @@ from core.constants import BANDS, UNKNOWN_BAND, CW_MODES, PHONE_MODES, DATA_MODE # requests_cache library to prevent re-downloading too quickly if the software keeps restarting. def download_country_files_cty_plist(): try: + logging.info("Downloading Country-files.com cty.plist...") response = COUNTRY_FILES_CTY_PLIST_CACHE.get("https://www.country-files.com/cty/cty.plist", headers=HTTP_HEADERS).text - # write to file with open(COUNTRY_FILES_CTY_PLIST_DOWNLOAD_LOCATION, "w") as f: f.write(response) return True @@ -36,13 +36,12 @@ def download_country_files_cty_plist(): # database live if possible. def download_clublog_ctyxml(): try: - # Read the file inside the .gz archive located at url + logging.info("Downloading Clublog cty.xml...") response = CLUBLOG_CTY_XML_CACHE.get("https://cdn.clublog.org/cty.php?api=" + CLUBLOG_API_KEY, headers=HTTP_HEADERS).raw with gzip.GzipFile(fileobj=response) as uncompressed: file_content = uncompressed.read() - # write to file in binary mode 'wb' with open(CLUBLOG_XML_DOWNLOAD_LOCATION, "wb") as f: f.write(file_content) return True @@ -57,6 +56,7 @@ def download_clublog_ctyxml(): # Clublog (XML download). The lookup functions iterate through these in a sensible order, looking for suitable data. COUNTRY_FILES_CTY_PLIST_CACHE = CachedSession("cache/country_files_city_plist_cache", expire_after=timedelta(days=10)) COUNTRY_FILES_CTY_PLIST_DOWNLOAD_LOCATION = "cache/cty.plist" +download_country_files_cty_plist() LOOKUP_LIB_BASIC = LookupLib(lookuptype="countryfile", filename=COUNTRY_FILES_CTY_PLIST_DOWNLOAD_LOCATION) CALL_INFO_BASIC = Callinfo(LOOKUP_LIB_BASIC)