44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""Configuration module - loads settings from .env file."""
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from typing import Optional
|
|
|
|
|
|
@dataclass
|
|
class Config:
|
|
"""Bot configuration."""
|
|
|
|
bot_token: str
|
|
db_url: str
|
|
log_level: str
|
|
timezone: str
|
|
polling_skip_updates: bool
|
|
|
|
@classmethod
|
|
def from_env(cls) -> "Config":
|
|
"""Load configuration from environment variables."""
|
|
bot_token = os.getenv("BOT_TOKEN")
|
|
if not bot_token:
|
|
raise ValueError("BOT_TOKEN environment variable is required")
|
|
|
|
return cls(
|
|
bot_token=bot_token,
|
|
db_url=os.getenv("DB_URL", "sqlite+aiosqlite:///data/reminder.db"),
|
|
log_level=os.getenv("LOG_LEVEL", "INFO"),
|
|
timezone=os.getenv("TZ", "Europe/Moscow"),
|
|
polling_skip_updates=os.getenv("POLLING_SKIP_UPDATES", "true").lower() == "true",
|
|
)
|
|
|
|
|
|
# Global config instance
|
|
config: Optional[Config] = None
|
|
|
|
|
|
def get_config() -> Config:
|
|
"""Get global config instance."""
|
|
global config
|
|
if config is None:
|
|
config = Config.from_env()
|
|
return config
|