We don't need to have loader.py in all projects
This commit is contained in:
parent
6ebbf6b907
commit
d6becb214e
39
loader.py
39
loader.py
|
@ -1,39 +0,0 @@
|
||||||
from aiogram import Bot
|
|
||||||
from aiogram.contrib.fsm_storage.memory import MemoryStorage
|
|
||||||
from aiogram.dispatcher import Dispatcher
|
|
||||||
|
|
||||||
from middlewares.database import DbMiddleware
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import asyncpg
|
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
||||||
|
|
||||||
import os
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import pretty_errors
|
|
||||||
|
|
||||||
|
|
||||||
async def create_pool(database, user, password: None):
|
|
||||||
return await asyncpg.create_pool(database=database,
|
|
||||||
user=user)
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
TOKEN = os.getenv("TOKEN")
|
|
||||||
DB_NAME = os.getenv("DB_NAME")
|
|
||||||
DB_USER = os.getenv("DB_USER")
|
|
||||||
DB_PASS = os.getenv("DB_PASS")
|
|
||||||
pool = loop.run_until_complete(create_pool(DB_NAME, DB_USER, DB_PASS))
|
|
||||||
|
|
||||||
bot = Bot(token=TOKEN)
|
|
||||||
dp = Dispatcher(bot, storage=MemoryStorage())
|
|
||||||
dp.middleware.setup(DbMiddleware(pool))
|
|
||||||
|
|
||||||
apscheduler_config = {
|
|
||||||
'apscheduler.jobstores.default': {
|
|
||||||
'type': 'sqlalchemy',
|
|
||||||
'url': 'sqlite:///cron_jobs.db'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scheduler = AsyncIOScheduler(apscheduler_config)
|
|
Reference in a new issue