Implement basic API server

This commit is contained in:
Ian Renton
2025-09-27 14:27:39 +01:00
parent 4077f835b7
commit 6d735cfc67
12 changed files with 130 additions and 28 deletions

View File

@@ -1,4 +1,3 @@
# Provides a timed cleanup of the spot list.
import logging
from datetime import datetime, timedelta
from threading import Timer
@@ -7,6 +6,7 @@ from time import sleep
import pytz
# Provides a timed cleanup of the spot list.
class CleanupTimer:
# Constructor

View File

@@ -6,6 +6,7 @@ SOFTWARE_VERSION = "0.1"
# Todo make configurable
SERVER_OWNER_CALLSIGN = "M0TRT"
WEB_SERVER_PORT = 8080
MAX_SPOT_AGE_SEC = 3600
# Modes

View File

@@ -1,6 +1,10 @@
from core.constants import BANDS, UNKNOWN_BAND, CW_MODES, PHONE_MODES, DATA_MODES, ALL_MODES
import logging
from datetime import datetime
from pyhamtools import LookupLib, Callinfo
from core.constants import BANDS, UNKNOWN_BAND, CW_MODES, PHONE_MODES, DATA_MODES, ALL_MODES
# Static lookup helpers from pyhamtools
# todo in future add QRZ as a second lookup option in case it provides more data?
lookuplib = LookupLib(lookuptype="countryfile")
@@ -23,7 +27,7 @@ def infer_mode_family_from_mode(mode):
return "DATA"
else:
if mode.upper() != "OTHER":
print("Found an unrecognised mode: " + mode + ". Developer should categorise this.")
logging.warn("Found an unrecognised mode: " + mode + ". Developer should categorise this.")
return None
# Infer a band from a frequency in kHz
@@ -66,4 +70,12 @@ def infer_itu_zone_from_callsign(call):
try:
return callinfo.get_ituz(call)
except KeyError as e:
return None
return None
# Convert objects to serialisable things. Used by JSON serialiser as a default when it encounters unserializable things.
# Converts datetimes to ISO.
# Anything else it tries to convert to a dict.
def serialize_everything(obj):
if isinstance(obj, datetime):
return obj.isoformat()
return obj.__dict__