mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Allow adding spots. Convert timestamps in the API to UNIX seconds. #2
This commit is contained in:
31
data/spot.py
31
data/spot.py
@@ -57,12 +57,16 @@ class Spot:
|
||||
freq: float = None
|
||||
# Band, defined by the frequency, e.g. "40m" or "70cm"
|
||||
band: str = None
|
||||
# Time of the spot
|
||||
time: datetime = None
|
||||
# Time that this software received the spot. This is used with the "since_received" call to our API to receive all
|
||||
# data that is new to us, even if by a quirk of the API it might be older than the list time the client polled the
|
||||
# API.
|
||||
received_time: datetime = datetime.now(pytz.UTC)
|
||||
# Time of the spot, UTC seconds since UNIX epoch
|
||||
time: float = None
|
||||
# Time of the spot, ISO 8601
|
||||
time_iso: str = None
|
||||
# Time that this software received the spot, UTC seconds since UNIX epoch. This is used with the "since_received"
|
||||
# call to our API to receive all data that is new to us, even if by a quirk of the API it might be older than the
|
||||
# list time the client polled the API.
|
||||
received_time: float = None
|
||||
# Time that this software received the spot, ISO 8601
|
||||
received_time_iso: str = None
|
||||
# Comment left by the spotter, if any
|
||||
comment: str = None
|
||||
# Special Interest Group (SIG), e.g. outdoor activity programme such as POTA
|
||||
@@ -96,9 +100,20 @@ class Spot:
|
||||
# Always create a GUID
|
||||
self.guid = str(uuid.uuid4())
|
||||
|
||||
# If we somehow don't have a time, set it to some far past value so it sorts at the bottom of the list
|
||||
# If we somehow don't have a spot time, set it to zero so it sorts off the bottom of any list but
|
||||
# clients can still reliably parse it as a number.
|
||||
if not self.time:
|
||||
self.time = datetime.min
|
||||
self.time = 0
|
||||
|
||||
# If we don't have a received time, this has just been received so set that to "now"
|
||||
if not self.received_time:
|
||||
self.received_time = datetime.now(pytz.UTC).timestamp()
|
||||
|
||||
# Fill in ISO versions of times, in case the client prefers that
|
||||
if self.time and not self.time_iso:
|
||||
self.time_iso = datetime.fromtimestamp(self.time, pytz.UTC).isoformat()
|
||||
if self.received_time and not self.received_time_iso:
|
||||
self.received_time_iso = datetime.fromtimestamp(self.received_time, pytz.UTC).isoformat()
|
||||
|
||||
# Clean up DX call if it has an SSID or -# from RBN
|
||||
if self.dx_call and "-" in self.dx_call:
|
||||
|
||||
Reference in New Issue
Block a user