Improve use of URL cache #118

This commit is contained in:
Ian Renton
2026-08-01 08:06:44 +01:00
parent fe10943ecc
commit c472872e10
5 changed files with 41 additions and 36 deletions
+6 -5
View File
@@ -17,7 +17,7 @@ from requests_cache import CachedSession
from core.config import config
from core.constants import BANDS, UNKNOWN_BAND, CW_MODES, PHONE_MODES, DATA_MODES, ALL_MODES, \
HTTP_HEADERS, HAMQTH_PRG, MODE_ALIASES
from core.url_data_cache import URL_DATA_CACHE
from core.url_data_cache import URLDataCache
# QRZ XML field names differ from pyhamtools' normalised names; map them here.
_QRZ_FIELD_MAP = {
@@ -29,6 +29,7 @@ _QRZ_FIELD_MAP = {
}
_QRZ_INT_FIELDS = {"adif", "cqz", "ituz"}
_QRZ_FLOAT_FIELDS = {"latitude", "longitude"}
_URL_DATA_CACHE = URLDataCache("callsign_lookup")
def _normalize_qrz_data(raw):
@@ -142,7 +143,7 @@ class LookupHelper:
try:
logging.info("Downloading Country-files.com cty.plist...")
response = URL_DATA_CACHE.get("https://www.country-files.com/cty/cty.plist",
response = _URL_DATA_CACHE.get("https://www.country-files.com/cty/cty.plist",
headers=HTTP_HEADERS)
if response.ok:
@@ -167,7 +168,7 @@ class LookupHelper:
try:
logging.info("Downloading dxcc.json...")
response = URL_DATA_CACHE.get(
response = _URL_DATA_CACHE.get(
"https://raw.githubusercontent.com/k0swe/dxcc-json/refs/heads/main/dxcc.json",
headers=HTTP_HEADERS)
@@ -515,7 +516,7 @@ class LookupHelper:
for lookup_call in calls_to_try:
try:
response = URL_DATA_CACHE.get(
response = _URL_DATA_CACHE.get(
self._qrz_base_url + "?s=" + session_key + "&callsign=" + urllib.parse.quote_plus(lookup_call),
headers=HTTP_HEADERS, timeout=10)
if response.ok:
@@ -593,7 +594,7 @@ class LookupHelper:
for lookup_call in calls_to_try:
try:
response = URL_DATA_CACHE.get(
response = _URL_DATA_CACHE.get(
self._hamqth_base_url + "?id=" + session_id + "&callsign=" + urllib.parse.quote_plus(
lookup_call) + "&prg=" + HAMQTH_PRG, headers=HTTP_HEADERS)
if response.ok: