changes related to aiohttp update

This commit is contained in:
odysseusmax 2021-11-02 21:22:00 +05:30
parent b5e876f393
commit 364417a65f
1 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,3 @@
import asyncio
import pathlib
import logging
@ -41,34 +40,35 @@ class Indexer:
secret_key=SECRET_KEY.encode(),
max_age=60 * SESSION_COOKIE_LIFETIME,
cookie_name="TG_INDEX_SESSION",
secure=True,
)
)
)
middlewares.append(middleware_factory())
self.server = web.Application(middlewares=middlewares)
self.loop = asyncio.get_event_loop()
self.server.on_startup.append(self.startup)
self.server.on_cleanup.append(self.cleanup)
self.tg_client = Client(session_string, api_id, api_hash)
self.server["is_authenticated"] = authenticated
self.server["username"] = username
self.server["password"] = password
async def startup(self):
async def startup(self, server: web.Application):
await self.tg_client.start()
log.debug("telegram client started!")
await setup_routes(self.server, Views(self.tg_client))
await setup_routes(server, Views(self.tg_client))
loader = jinja2.FileSystemLoader(str(self.TEMPLATES_ROOT))
aiohttp_jinja2.setup(self.server, loader=loader)
aiohttp_jinja2.setup(server, loader=loader)
self.server.on_cleanup.append(self.cleanup)
async def cleanup(self, *args):
async def cleanup(self, server: web.Application):
await self.tg_client.disconnect()
log.debug("telegram client disconnected!")
def run(self):
self.loop.run_until_complete(self.startup())
web.run_app(self.server, host=host, port=port)