mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-05 18:11:41 +00:00
Refactor of caching & data storage part 15 #118
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ class HamQTH(APIQueryCallsignDataProvider):
|
|||||||
expire_after=timedelta(minutes=55))
|
expire_after=timedelta(minutes=55))
|
||||||
|
|
||||||
def _perform_new_lookup(self, callsign, lookup_credentials):
|
def _perform_new_lookup(self, callsign, lookup_credentials):
|
||||||
# If we don't have HamQTH credentials, skip this lookup
|
# If we don't have HamQTH credentials, skip this lookup Return None so we don't *cache* the lack of data, because
|
||||||
|
# # someone might provide credentials next time around.
|
||||||
if not lookup_credentials or not ((lookup_credentials.hamqth_username and lookup_credentials.hamqth_password)
|
if not lookup_credentials or not ((lookup_credentials.hamqth_username and lookup_credentials.hamqth_password)
|
||||||
or lookup_credentials.hamqth_session_key):
|
or lookup_credentials.hamqth_session_key):
|
||||||
return None
|
return None
|
||||||
@@ -75,6 +76,8 @@ class HamQTH(APIQueryCallsignDataProvider):
|
|||||||
self._HAMQTH_BASE_URL + "?id=" + session_key + "&callsign=" + urllib.parse.quote_plus(
|
self._HAMQTH_BASE_URL + "?id=" + session_key + "&callsign=" + urllib.parse.quote_plus(
|
||||||
lookup_call) + "&prg=" + self._PRG, headers=HTTP_HEADERS, timeout=10)
|
lookup_call) + "&prg=" + self._PRG, headers=HTTP_HEADERS, timeout=10)
|
||||||
if response.ok:
|
if response.ok:
|
||||||
|
self.status = "OK"
|
||||||
|
self.last_update_time = datetime.now(pytz.UTC)
|
||||||
data = xmltodict.parse(response.content)["HamQTH"]["search"]
|
data = xmltodict.parse(response.content)["HamQTH"]["search"]
|
||||||
# Found data, convert it to our object and return it
|
# Found data, convert it to our object and return it
|
||||||
return self.hamqth_response_to_callsign(callsign, data)
|
return self.hamqth_response_to_callsign(callsign, data)
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ class QRZ(APIQueryCallsignDataProvider):
|
|||||||
expire_after=timedelta(minutes=55))
|
expire_after=timedelta(minutes=55))
|
||||||
|
|
||||||
def _perform_new_lookup(self, callsign, lookup_credentials):
|
def _perform_new_lookup(self, callsign, lookup_credentials):
|
||||||
# If we don't have QRZ credentials, skip this lookup
|
# If we don't have QRZ credentials, skip this lookup. Return None so we don't *cache* the lack of data, because
|
||||||
|
# someone might provide credentials next time around.
|
||||||
if not lookup_credentials or not ((lookup_credentials.qrz_username and lookup_credentials.qrz_password)
|
if not lookup_credentials or not ((lookup_credentials.qrz_username and lookup_credentials.qrz_password)
|
||||||
or lookup_credentials.qrz_session_key):
|
or lookup_credentials.qrz_session_key):
|
||||||
return None
|
return None
|
||||||
@@ -77,6 +78,8 @@ class QRZ(APIQueryCallsignDataProvider):
|
|||||||
qrz_response = xmltodict.parse(response.content).get("QRZDatabase", {})
|
qrz_response = xmltodict.parse(response.content).get("QRZDatabase", {})
|
||||||
if qrz_response:
|
if qrz_response:
|
||||||
if "Callsign" in qrz_response:
|
if "Callsign" in qrz_response:
|
||||||
|
self.status = "OK"
|
||||||
|
self.last_update_time = datetime.now(pytz.UTC)
|
||||||
# Found data, convert it to our object and return it
|
# Found data, convert it to our object and return it
|
||||||
return self.qrz_response_to_callsign(callsign, qrz_response.get("Callsign"))
|
return self.qrz_response_to_callsign(callsign, qrz_response.get("Callsign"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user