homekit/bin/web_kbn.py
Evgeny Zinoviev 405a17a9fd save
2023-09-13 09:34:49 +03:00

59 lines
1.5 KiB
Python

#!/usr/bin/env python3
import asyncio
import jinja2
import aiohttp_jinja2
import os
import __py_include
from typing import Optional
from homekit.config import config, AppConfigUnit
from homekit.util import homekit_path
from aiohttp import web
from homekit import http
class WebKbnConfig(AppConfigUnit):
NAME = 'web_kbn'
@classmethod
def schema(cls) -> Optional[dict]:
return {
'listen_addr': cls._addr_schema(required=True)
}
class WebSite(http.HTTPServer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
aiohttp_jinja2.setup(
self.app,
loader=jinja2.FileSystemLoader(homekit_path('web', 'kbn_templates'))
)
self.get('/', self.get_index)
@staticmethod
async def get_index(req: http.Request):
# context = {
# 'username': request.match_info.get("username", ""),
# 'current_date': 'January 27, 2017'
# }
# response = aiohttp_jinja2.render_template("example.html", request,
# context=context)
# return response
message = "nothing here, keep lurking"
return http.Response(text=message, content_type='text/plain')
if __name__ == '__main__':
config.load_app(WebKbnConfig)
loop = asyncio.get_event_loop()
# print(config.app_config)
print(config.app_config['listen_addr'].host)
server = WebSite(config.app_config['listen_addr'])
server.run()