51 lines
1002 B
Python
51 lines
1002 B
Python
|
from pydantic import BaseModel
|
||
|
from pydantic_settings import (
|
||
|
BaseSettings,
|
||
|
SettingsConfigDict,
|
||
|
)
|
||
|
|
||
|
from pathlib import Path
|
||
|
|
||
|
import logging
|
||
|
|
||
|
|
||
|
BASE_DIR = Path(__file__).parent.parent
|
||
|
|
||
|
|
||
|
class TGSettings(BaseModel):
|
||
|
token: str = ""
|
||
|
|
||
|
|
||
|
class ZaqbbixAPI(BaseModel):
|
||
|
token: str = ""
|
||
|
url: str = ""
|
||
|
|
||
|
|
||
|
class Settings(BaseSettings):
|
||
|
model_config = SettingsConfigDict(
|
||
|
env_file=(
|
||
|
BASE_DIR / "tg-bot-app" / ".env-template",
|
||
|
BASE_DIR / "tg-bot-app" / ".env",
|
||
|
),
|
||
|
case_sensitive=False,
|
||
|
env_nested_delimiter="__",
|
||
|
env_prefix="TGBOT_CONFIG__",
|
||
|
)
|
||
|
|
||
|
tg: TGSettings = TGSettings()
|
||
|
zbx: ZaqbbixAPI = ZaqbbixAPI()
|
||
|
|
||
|
|
||
|
settings = Settings()
|
||
|
|
||
|
|
||
|
def config_logging(level=logging.INFO):
|
||
|
logging.basicConfig(
|
||
|
level=level,
|
||
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||
|
format="[%(asctime)s.%(msecs)03d] %(module)-15s:%(lineno)4d | %(funcName)-20s| %(levelname)-8s | %(message)s",
|
||
|
)
|
||
|
|
||
|
|
||
|
config_logging(level=logging.INFO)
|