feat: add project infrastructure

- Add src/ structure with config and logger modules
- Add .env.example with required environment variables
- Add python-dotenv dependency
- Add TASK.md with implementation roadmap
This commit is contained in:
2026-02-02 20:42:12 +03:00
parent 52d5e54bfe
commit c289d9c54e
9 changed files with 89 additions and 5 deletions

0
src/__init__.py Normal file
View File

25
src/config.py Normal file
View File

@@ -0,0 +1,25 @@
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
def _get_env(key: str) -> str:
"""Получает переменную окружения или выбрасывает ошибку."""
value = os.getenv(key)
if value is None:
raise RuntimeError(f"Переменная окружения {key} не задана")
return value
BOT_TOKEN: str = _get_env("BOT_TOKEN")
ADMIN_LOGIN: str = _get_env("ADMIN_LOGIN")
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
BASE_DIR: Path = Path(__file__).parent.parent
DATA_DIR: Path = BASE_DIR / "data"
DATA_PARTIAL_DIR: Path = BASE_DIR / "data_partial"
SCENARIOS_DIR: Path = BASE_DIR / "scenarios"
DB_PATH: Path = BASE_DIR / "bot.db"

25
src/logger.py Normal file
View File

@@ -0,0 +1,25 @@
import logging
import sys
from src.config import LOG_LEVEL
def setup_logger() -> logging.Logger:
"""Настраивает и возвращает логгер приложения."""
logger = logging.getLogger("bot")
logger.setLevel(LOG_LEVEL)
if not logger.handlers:
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(LOG_LEVEL)
formatter = logging.Formatter(
"%(asctime)s | %(levelname)-8s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
logger = setup_logger()