Refactor of caching & data storage part 11 #118

This commit is contained in:
Ian Renton
2026-08-02 12:38:33 +01:00
parent 2e6d8e4b4a
commit cee9188538
8 changed files with 108 additions and 41 deletions
+43
View File
@@ -0,0 +1,43 @@
import logging
from datetime import datetime
import pytz
from pyhamtools import LookupLib, Callinfo
from core.utils import get_callsign_object_from_pyhamtools_callinfo
from data.callsign import Callsign
from providers.callsigndata.api_query_callsign_data_provider import APIQueryCallsignDataProvider
class ClublogAPI(APIQueryCallsignDataProvider):
"""Callsign data provider for Clublog's API."""
_callinfo = None
def __init__(self, provider_config):
# API key required for this provider
self._api_key = provider_config.get("api-key", "")
if self._api_key != "":
lookuplib = LookupLib(lookuptype="clublogapi", apikey=self._api_key)
self._callinfo = Callinfo(lookuplib)
else:
provider_config["enabled"] = False
logging.warning(
"Clublog XML callsign data provider configured but no api key was provided, this has been disabled.")
super().__init__("Clublog API", provider_config)
def lookup(self, callsign, lookup_credentials):
callsign_data = Callsign(call=callsign)
try:
callsign_data = get_callsign_object_from_pyhamtools_callinfo(callsign, self._callinfo)
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
except Exception as e:
self.status = "Error"
logging.error("Exception when looking up data from Clublog API", e, exc_info=True)
return callsign_data