-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
44 lines (34 loc) · 1.29 KB
/
Copy pathsettings.py
File metadata and controls
44 lines (34 loc) · 1.29 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
from aiogram import Bot, Dispatcher
from aiogram.enums import ParseMode
from aiogram.client.default import DefaultBotProperties
from aiogram.fsm.storage.memory import MemoryStorage, SimpleEventIsolation
from aiogram.utils.token import TokenValidationError
from dotenv import load_dotenv
from typing import Final
import logging
import os
import sys
from orm import ORM
from Google import GSheets
def load_envFile(env_file: str) -> None:
if os.path.isfile(env_file):
load_dotenv(dotenv_path=env_file)
logging.info("Environment file connected.")
else:
logging.critical("Didn't found Environment file")
sys.exit(1)
logging.basicConfig(level=logging.INFO)
ENV_BASE_DIR = "environments/template/"
load_envFile(ENV_BASE_DIR + '.env')
try:
bot: Final = Bot(token=os.getenv("BOT_TOKEN"), default=DefaultBotProperties(parse_mode=ParseMode.HTML))
except TokenValidationError:
logging.critical("The token is undefined or invalid. Check .env file")
sys.exit(1)
dp: Dispatcher = Dispatcher(storage=MemoryStorage(), events_isolation=SimpleEventIsolation())
sheet: GSheets = GSheets(path_to_credentials=ENV_BASE_DIR + 'google-service.json')
async def on_startup():
await ORM.orm_init()
async def on_shutdown():
await ORM.orm_shutdown()
await dp.storage.close()