Implement more request handlers in Tornado #3

This commit is contained in:
Ian Renton
2025-12-23 14:05:28 +00:00
parent 61784e8af6
commit 23a6e08777
9 changed files with 336 additions and 607 deletions

View File

@@ -16,8 +16,9 @@ class APISpotsHandler(tornado.web.RequestHandler):
def get(self):
try:
# request.arguments contains lists for each param key because technically the client can supply multiple,
# reduce that to just the first entry
query_params = {k: v[0] for k, v in self.request.arguments.items()}
# reduce that to just the first entry, and convert bytes to string
query_params = {k: v[0].decode("utf-8") for k, v in self.request.arguments.items()}
# Fetch all spots matching the query
data = get_spot_list_with_filters(self.spots, query_params)
self.write(json.dumps(data, default=serialize_everything))
@@ -38,7 +39,22 @@ class APISpotsHandler(tornado.web.RequestHandler):
class APISpotsStreamHandler(tornado.web.RequestHandler):
def get(self):
# todo
self.write("Hello, world")
# try:
# response.content_type = 'text/event-stream'
# response.cache_control = 'no-cache'
# yield 'retry: 1000\n\n'
#
# spot_queue = Queue(maxsize=100)
# self.sse_spot_queues.append(spot_queue)
# while True:
# if spot_queue.empty():
# gevent.sleep(1)
# else:
# spot = spot_queue.get()
# yield 'data: ' + json.dumps(spot, default=serialize_everything) + '\n\n'
# except Exception as e:
# logging.warn("Exception when serving SSE socket", e)
pass