mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Download country-files.com cty.plist separately so we can cache the result and handle exceptions
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from core.config import SERVER_OWNER_CALLSIGN
|
||||
from data.band import Band
|
||||
|
||||
# General software
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user