-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (29 loc) · 975 Bytes
/
main.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
import asyncio
import traceback
from os import getenv
from typing import Optional
from dotenv import load_dotenv
from tortoise import Tortoise, connections
from utils.client import CryptoBot
load_dotenv(override=True)
client: Optional[CryptoBot] = None
async def init():
await Tortoise.init(db_url="sqlite://main.db", modules={"models": ["utils.models"]})
await Tortoise.generate_schemas()
global client
client = CryptoBot()
token = getenv("TOKEN")
await client.start(token)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(init())
except (KeyboardInterrupt, Exception) as e:
if not isinstance(e, KeyboardInterrupt):
traceback.print_exc()
loop.run_until_complete(connections.close_all())
if client and not client.is_closed():
loop.run_until_complete(client.close())
finally:
if loop.is_running():
loop.close()