mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 09:14:30 +00:00
Implement more request handlers in Tornado #3
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user