1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/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()
|