From 69e0ba0a8db8e25bfca0b499975bf0028232b4c1 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sun, 28 Sep 2025 17:35:54 +0100 Subject: [PATCH] Starting to implement queries for the JSON endpoint --- providers/wwbota.py | 2 +- server/webserver.py | 15 ++++++++++++--- webassets/js/code.js | 5 +++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/providers/wwbota.py b/providers/wwbota.py index d20aeb6..cb0f1a3 100644 --- a/providers/wwbota.py +++ b/providers/wwbota.py @@ -5,7 +5,7 @@ from providers.http_provider import HTTPProvider # Provider for Worldwide Bunkers on the Air -# todo switch to event source API as per Steve change to Field Spotter +# todo switch to event source API as per Steve change to Field Spotter, if Python supports it class WWBOTA(HTTPProvider): POLL_INTERVAL_SEC = 120 SPOTS_URL = "https://api.wwbota.org/spots/" diff --git a/server/webserver.py b/server/webserver.py index 4254e95..db90e81 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -44,7 +44,7 @@ class WebServer: def serve_api_spots(self): self.last_api_access_time = datetime.now(pytz.UTC) self.status = "OK" - spots_json = json.dumps(self.spot_list, default=serialize_everything) + spots_json = json.dumps(self.get_spot_list_with_filters(bottle.request.query), default=serialize_everything) response.content_type = 'application/json' return spots_json @@ -66,7 +66,16 @@ class WebServer: def serve_static_file(self, filepath): return bottle.static_file(filepath, root="webassets") + # Utility method to apply filters to the overall spot list and return only a subset. Enables query parameters in + # the main "spots" GET call. The "query" parameter should be the result of bottle's request.query, and is a MultiDict + def get_spot_list_with_filters(self, query): + spot_subset = self.spot_list[:] + for k in query.keys(): + print(k + ": " + query.get(k)) + return spot_subset -# Todo spot API arguments e.g. "since" based on received_time of spots, sources, sigs, dx cont, dxcc, de cont, band, mode, filter out qrt, filter pre-qsy, sort order, list of fields -# Todo serve status API + + + +# Todo serve Server-Sent Events to frontend - see https://medium.com/@tdenton8772/streaming-api-design-using-python-and-javascript-1b0ce8adb703 # Todo serve apidocs \ No newline at end of file diff --git a/webassets/js/code.js b/webassets/js/code.js index dbbfe8c..53fd0c8 100644 --- a/webassets/js/code.js +++ b/webassets/js/code.js @@ -1,6 +1,7 @@ -// TODO get all data into JS +// TODO get all data into JS on first load +// TODO subscribe to SSE to get updates, merge with local data, sort, refresh display +// TODO cap at a sensible number of lines in the table, throw away other data, make the number configurable // TODO populate table more nicely -// TODO track last received time and use API since call, merge and sort local data, refresh display // TODO filtering (applied locally) // TODO look and feel