mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Refactor of caching & data storage part 14 #118
This commit is contained in:
+20
-27
@@ -1,21 +1,4 @@
|
||||
import gzip
|
||||
import logging
|
||||
import urllib.parse
|
||||
from datetime import timedelta
|
||||
|
||||
import xmltodict
|
||||
from diskcache import Cache
|
||||
from pyhamtools import LookupLib, Callinfo, callinfo
|
||||
from pyhamtools.exceptions import APIKeyMissingError
|
||||
from pyhamtools.locator import latlong_to_locator
|
||||
from requests.exceptions import ConnectionError, ReadTimeout, ConnectTimeout
|
||||
from requests_cache import CachedSession
|
||||
|
||||
from core.config import config
|
||||
from core.constants import HTTP_HEADERS, HAMQTH_PRG
|
||||
from core.data_providers import DATA_PROVIDERS
|
||||
from core.data_store import DATA_STORE
|
||||
from core.url_data_cache import URLDataCache
|
||||
from data.callsign import Callsign
|
||||
|
||||
|
||||
@@ -24,14 +7,24 @@ def get_call_info(callsign, lookup_credentials):
|
||||
lookup_credentials is an optional object that carries the user's QRZ.com/HamQTH credentials, if they provided them,
|
||||
to enable lookup using those providers."""
|
||||
|
||||
callsign = Callsign(call=callsign)
|
||||
for p in DATA_PROVIDERS.callsign_data_providers:
|
||||
# Get new lookup data
|
||||
data = p.lookup(callsign, lookup_credentials)
|
||||
if data:
|
||||
# Merge in turn, replacing any existing content where we have it.
|
||||
for key, value in data.__dict__.items():
|
||||
if value is not None:
|
||||
callsign.__dict__[key] = value
|
||||
callsign_data = Callsign(call=callsign)
|
||||
|
||||
return callsign
|
||||
if callsign:
|
||||
# Sort callsign providers by priority order, so we query the highest priority (lowest numbers) first, and only
|
||||
# query other providers for data we are missing as we go along.
|
||||
for p in sorted(DATA_PROVIDERS.callsign_data_providers, key=lambda p: p.priority):
|
||||
if p.enabled:
|
||||
# Get new lookup data
|
||||
data = p.lookup(callsign, lookup_credentials)
|
||||
if data:
|
||||
# If we have new data for fields that were previously unpopulated, add them in
|
||||
for key, value in data.__dict__.items():
|
||||
if value is not None and callsign_data.__dict__.get(key) is None:
|
||||
callsign_data.__dict__[key] = value
|
||||
|
||||
# If callsign data is fully populated, avoid looking up using other providers as their data will not
|
||||
# be used
|
||||
if callsign_data.fully_populated():
|
||||
break
|
||||
|
||||
return callsign_data
|
||||
Reference in New Issue
Block a user