Run and stop the bot correctly
This commit is contained in:
parent
58bf722a97
commit
a7d6626b12
19
bot.py
19
bot.py
|
@ -1,10 +1,25 @@
|
|||
#!/usr/bin/python
|
||||
from aiogram import executor
|
||||
import logging
|
||||
import os
|
||||
|
||||
import asyncio
|
||||
from aiogram import Bot, Dispatcher
|
||||
|
||||
|
||||
async def main():
|
||||
"""TODO: Create and configure bot, connect to db"""
|
||||
"""Configures and runs the bot, connects to the db"""
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
API_TOKEN = os.getenv("API_TOKEN")
|
||||
|
||||
bot = Bot(API_TOKEN)
|
||||
dp = Dispatcher(bot)
|
||||
|
||||
try:
|
||||
await dp.start_polling()
|
||||
finally:
|
||||
await dp.storage.close()
|
||||
await dp.storage.wait_closed()
|
||||
await bot.session.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Reference in a new issue