diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2024-02-19 01:44:02 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2024-02-19 01:44:11 +0300 |
commit | 3741f7cf78a288e967415ccb6736c888a21c211b (patch) | |
tree | a48d8331c9936d6c108de4d0f9179a089b1e56e6 /bin/web_api.py | |
parent | d79309e498cdc1358c81367ce2a93a5731e517d1 (diff) |
web_kbn: almost completely ported lws to python
Diffstat (limited to 'bin/web_api.py')
-rwxr-xr-x | bin/web_api.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/bin/web_api.py b/bin/web_api.py index d221838..1804b30 100755 --- a/bin/web_api.py +++ b/bin/web_api.py @@ -51,7 +51,7 @@ class WebAPIServer(http.HTTPServer): @staticmethod @web.middleware - async def validate_auth(req: http.Request, handler): + async def validate_auth(req: web.Request, handler): def get_token() -> str: name = 'X-Token' if name in req.headers: @@ -70,13 +70,13 @@ class WebAPIServer(http.HTTPServer): return await handler(req) @staticmethod - async def get_index(req: http.Request): + async def get_index(req: web.Request): message = "nothing here, keep lurking" if is_development_mode(): message += ' (dev mode)' - return http.Response(text=message, content_type='text/plain') + return web.Response(text=message, content_type='text/plain') - async def GET_sensors_data(self, req: http.Request): + async def GET_sensors_data(self, req: web.Request): try: hours = int(req.query['hours']) if hours < 1 or hours > 24: @@ -93,7 +93,7 @@ class WebAPIServer(http.HTTPServer): data = db.get_temperature_recordings(sensor, (dt_from, dt_to)) return self.ok(data) - async def GET_sound_sensors_hits(self, req: http.Request): + async def GET_sound_sensors_hits(self, req: web.Request): location = SoundSensorLocation(int(req.query['location'])) after = int(req.query['after']) @@ -112,7 +112,7 @@ class WebAPIServer(http.HTTPServer): data = BotsDatabase().get_sound_hits(location, **kwargs) return self.ok(data) - async def POST_sound_sensors_hits(self, req: http.Request): + async def POST_sound_sensors_hits(self, req: web.Request): hits = [] data = await req.post() for hit, count in json.loads(data['hits']): @@ -125,7 +125,7 @@ class WebAPIServer(http.HTTPServer): BotsDatabase().add_sound_hits(hits, datetime.now()) return self.ok() - async def POST_openwrt_log(self, req: http.Request): + async def POST_openwrt_log(self, req: web.Request): data = await req.post() try: @@ -154,7 +154,7 @@ class WebAPIServer(http.HTTPServer): BotsDatabase().add_openwrt_logs(lines, ap) return self.ok() - async def GET_recordings_list(self, req: http.Request): + async def GET_recordings_list(self, req: web.Request): data = await req.post() try: @@ -176,7 +176,7 @@ class WebAPIServer(http.HTTPServer): return self.ok(files) @staticmethod - def _get_inverter_from_to(req: http.Request): + def _get_inverter_from_to(req: web.Request): s_from = req.query['from'] s_to = req.query['to'] @@ -189,12 +189,12 @@ class WebAPIServer(http.HTTPServer): return dt_from, dt_to - async def GET_consumed_energy(self, req: http.Request): + async def GET_consumed_energy(self, req: web.Request): dt_from, dt_to = self._get_inverter_from_to(req) wh = InverterDatabase().get_consumed_energy(dt_from, dt_to) return self.ok(wh) - async def GET_grid_consumed_energy(self, req: http.Request): + async def GET_grid_consumed_energy(self, req: web.Request): dt_from, dt_to = self._get_inverter_from_to(req) wh = InverterDatabase().get_grid_consumed_energy(dt_from, dt_to) return self.ok(wh) |