-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·49 lines (41 loc) · 1.18 KB
/
main.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.18 KB
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
from aiohttp import web
import os
import importlib
import logging
import _config_
from middlewares import setup_middlewares
logging.basicConfig(filename='log.log', level=logging.DEBUG)
class main(web.Application):
def __init__(self, app):
self.app = app
def index(self):
return web.FileResponse('./static/html/index.html')
def start(self):
handles, cogs, routes = self.loadAllHandles()
print(f"loaded cogs:")
print(cogs, "\n")
print(f"loaded handles:")
print(handles, "\n")
print("routes")
print(routes, "\n")
self.index()
web.run_app(self.app, port=8080)
def loadAllHandles(self):
global cogs
_cogs = {}
_routes = []
for handle in os.listdir(r"./handlers"):
if handle[-3:] == ".py":
cog, handles = importlib.import_module(
f"handlers.{handle[:-3]}").setup(self.app)
_cogs[handle[:-3]] = [cog, handles]
for cog in _cogs:
for handle in _cogs[cog][1]:
self.app.router.add_get(f"{_cogs[cog][1][handle]}",
getattr(_cogs[cog][0], handle))
_routes.append(f"{_cogs[cog][1][handle]}")
return handles, _cogs, _routes
if __name__ == "__main__":
app = web.Application()
setup_middlewares(app)
main(app).start()