-
Notifications
You must be signed in to change notification settings - Fork 1
/
dashboard.py
58 lines (38 loc) · 1.13 KB
/
dashboard.py
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
from web import context
from sanic import Sanic
from sanic.response import text
from sanic_ext import render
from utils import db
from config import config
from web.blueprints.blueprints import dash
from oauth import Client
from os import walk
config = config.DashboardConfig()
_oauth_client = Client(config.client_id, secret=config.client_secret, redirect=config.callback_url)
_db = db.DB(db.mariadb_pool(0))
app = Sanic("LanaDashboard")
app.static('/static', './dashboard/static')
app.ctx = context.CustomContext(_db)
app.blueprint(dash)
html_data = {}
async def render_jinja_file(file_name: str, context: dict):
return await render(
template_source=html_data[file_name],
context=context,
app=app,
)
for parent, subddirs, files in walk("./web/html/"):
for file in files:
html_data[file] = open(f"{parent}{file}").read()
@app.get("/")
async def hello_world(request):
return text("Hello, world.")
# Inject everything needed.
@app.on_request
async def setup_connection(request):
request.ctx.oauth = _oauth_client
request.ctx.render = render_jinja_file
def main():
app.run("localhost", 8080)
if __name__ == '__main__':
main()