mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Further alert implementation #17
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import hashlib
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
|
||||
import copy
|
||||
import pytz
|
||||
|
||||
from core.constants import DXCC_FLAGS
|
||||
@@ -14,7 +16,7 @@ from core.utils import infer_continent_from_callsign, \
|
||||
@dataclass
|
||||
class Alert:
|
||||
# Unique identifier for the alert
|
||||
id: int = None
|
||||
id: str = None
|
||||
# Callsign of the operator that has been alertted
|
||||
dx_call: str = None
|
||||
# Name of the operator that has been alertted
|
||||
@@ -103,8 +105,15 @@ class Alert:
|
||||
if self.dx_call and not self.dx_name:
|
||||
self.dx_name = infer_name_from_callsign(self.dx_call)
|
||||
|
||||
# Always create an ID based on a hashcode
|
||||
self.id = hash(str(self))
|
||||
# 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()
|
||||
|
||||
# JSON serialise
|
||||
def to_json(self):
|
||||
|
||||
Reference in New Issue
Block a user