Starting to implement queries for the JSON endpoint

This commit is contained in:
Ian Renton
2025-09-28 17:35:54 +01:00
parent bcda5769ee
commit 69e0ba0a8d
3 changed files with 16 additions and 6 deletions

View File

@@ -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