Add options API #15

This commit is contained in:
Ian Renton
2025-09-30 21:29:17 +01:00
parent 37692f41a8
commit 4f4c1a9191
5 changed files with 658540 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import bottle
import pytz
from bottle import run, response
from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, SOURCES, CONTINENTS
from core.utils import serialize_everything
@@ -26,6 +27,7 @@ class WebServer:
# Set up routing
bottle.get("/api/spots")(self.serve_api_spots)
bottle.get("/api/options")(self.serve_api_options)
bottle.get("/api/status")(self.serve_api_status)
bottle.get("/")(self.serve_index)
bottle.get("/apidocs")(self.serve_apidocs)
@@ -49,6 +51,14 @@ class WebServer:
response.content_type = 'application/json'
return spots_json
# Options API
def serve_api_options(self):
self.last_api_access_time = datetime.now(pytz.UTC)
self.status = "OK"
status_json = json.dumps(self.get_options(), default=serialize_everything)
response.content_type = 'application/json'
return status_json
# Server status API
def serve_api_status(self):
self.last_api_access_time = datetime.now(pytz.UTC)
@@ -118,3 +128,14 @@ class WebServer:
if "limit" in query.keys():
spots = spots[:int(query.get("limit"))]
return spots
# Return all the "options" for various things that the server is aware of. This can be fetched with an API call.
# The idea is that this will include most of the things that can be provided as queries to the main spots call,
# and thus a client can use this data to configure its filter controls.
def get_options(self):
return {"bands": BANDS,
"modes": ALL_MODES,
"mode_types": MODE_TYPES,
"sigs": SIGS,
"sources": SOURCES,
"continents": CONTINENTS}