mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Implement basic API server
This commit is contained in:
@@ -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__
|
||||
Reference in New Issue
Block a user