Files
spothole/core/call_lookup_helper.py
T

37 lines
1.4 KiB
Python

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
def get_call_info(callsign, lookup_credentials):
"""Utility method to get the best set of data for a callsign as we can, using all enabled providers.
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
return callsign