mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-05-30 17:35:11 +00:00
Modify the backend so that instead of using the server owner's QRZ & HamQTH credentials, it instead requires them to be provided by the client (if none are provided, the lookups do not occur.)
This commit is contained in:
@@ -61,7 +61,7 @@ class Alert:
|
||||
# The ID the source gave it, if any.
|
||||
source_id: str = None
|
||||
|
||||
def infer_missing(self):
|
||||
def infer_missing(self, credentials=None):
|
||||
"""Infer missing parameters where possible"""
|
||||
|
||||
# If we somehow don't have a start time, set it to zero so it sorts off the bottom of any list but
|
||||
@@ -84,15 +84,15 @@ class Alert:
|
||||
# DX country, continent, zones etc. from callsign. CQ/ITU zone are better looked up with a location but we don't
|
||||
# have a real location for alerts.
|
||||
if self.dx_calls and self.dx_calls[0] and not self.dx_country:
|
||||
self.dx_country = lookup_helper.infer_country_from_callsign(self.dx_calls[0])
|
||||
self.dx_country = lookup_helper.infer_country_from_callsign(self.dx_calls[0], credentials)
|
||||
if self.dx_calls and self.dx_calls[0] and not self.dx_continent:
|
||||
self.dx_continent = lookup_helper.infer_continent_from_callsign(self.dx_calls[0])
|
||||
self.dx_continent = lookup_helper.infer_continent_from_callsign(self.dx_calls[0], credentials)
|
||||
if self.dx_calls and self.dx_calls[0] and not self.dx_cq_zone:
|
||||
self.dx_cq_zone = lookup_helper.infer_cq_zone_from_callsign(self.dx_calls[0])
|
||||
self.dx_cq_zone = lookup_helper.infer_cq_zone_from_callsign(self.dx_calls[0], credentials)
|
||||
if self.dx_calls and self.dx_calls[0] and not self.dx_itu_zone:
|
||||
self.dx_itu_zone = lookup_helper.infer_itu_zone_from_callsign(self.dx_calls[0])
|
||||
self.dx_itu_zone = lookup_helper.infer_itu_zone_from_callsign(self.dx_calls[0], credentials)
|
||||
if self.dx_calls and self.dx_calls[0] and not self.dx_dxcc_id:
|
||||
self.dx_dxcc_id = lookup_helper.infer_dxcc_id_from_callsign(self.dx_calls[0])
|
||||
self.dx_dxcc_id = lookup_helper.infer_dxcc_id_from_callsign(self.dx_calls[0], credentials)
|
||||
if self.dx_dxcc_id and not self.dx_flag:
|
||||
self.dx_flag = lookup_helper.get_flag_for_dxcc(self.dx_dxcc_id)
|
||||
|
||||
@@ -108,21 +108,25 @@ class Alert:
|
||||
if self.sig_refs and len(self.sig_refs) > 0 and self.sig_refs[0] and not self.sig:
|
||||
self.sig = self.sig_refs[0].sig
|
||||
|
||||
# DX operator details lookup, using QRZ.com. This should be the last resort compared to taking the data from
|
||||
# the actual alertting service, e.g. we don't want to accidentally use a user's QRZ.com home lat/lon instead of
|
||||
# the one from the park reference they're at.
|
||||
if self.dx_calls and not self.dx_names:
|
||||
self.dx_names = list(map(lambda c: lookup_helper.infer_name_from_callsign_online_lookup(c), self.dx_calls))
|
||||
|
||||
# Always create an ID based on a hash of every parameter *except* received_time. This is used as the index
|
||||
# to a map, which as a byproduct avoids us having multiple duplicate copies of the object that are identical
|
||||
# apart from that they were retrieved from the API at different times. Note that the simple Python hash()
|
||||
# function includes a seed randomly generated at runtime; this is therefore not consistent between runs. But we
|
||||
# use diskcache to store our data between runs, so we use SHA256 which does not include this random element.
|
||||
self_copy = copy.deepcopy(self)
|
||||
self_copy.received_time = 0
|
||||
self_copy.received_time_iso = ""
|
||||
self.id = hashlib.sha256(str(self_copy).encode("utf-8")).hexdigest()
|
||||
# The ID is computed before the online lookups below so that it is stable regardless of whether credentials
|
||||
# are provided, allowing the enriched API response to be matched to the stored alert by ID.
|
||||
if not self.id:
|
||||
self_copy = copy.deepcopy(self)
|
||||
self_copy.received_time = 0
|
||||
self_copy.received_time_iso = ""
|
||||
self.id = hashlib.sha256(str(self_copy).encode("utf-8")).hexdigest()
|
||||
|
||||
# DX operator details lookup, using QRZ.com/HamQTH. This should be the last resort compared to taking the data
|
||||
# from the actual alerting service, e.g. we don't want to accidentally use a user's QRZ.com home lat/lon
|
||||
# instead of the one from the park reference they're at.
|
||||
if self.dx_calls and not self.dx_names:
|
||||
self.dx_names = list(
|
||||
map(lambda c: lookup_helper.infer_name_from_callsign_online_lookup(c, credentials), self.dx_calls))
|
||||
|
||||
def to_json(self):
|
||||
"""JSON serialise"""
|
||||
|
||||
Reference in New Issue
Block a user