70 lines
1.3 KiB
Python
70 lines
1.3 KiB
Python
from dataclasses import dataclass
|
|
from typing import List, Optional
|
|
import yaml
|
|
|
|
|
|
@dataclass
|
|
class SmtpConfig:
|
|
server: str
|
|
port: int
|
|
use_ssl: bool = True
|
|
use_starttls: bool = False
|
|
|
|
|
|
@dataclass
|
|
class EmailAccount:
|
|
imap_server: str
|
|
imap_port: int
|
|
username: str
|
|
password: str
|
|
use_ssl: bool = True
|
|
use_starttls: bool = False
|
|
smtp: Optional[SmtpConfig] = None
|
|
|
|
|
|
@dataclass
|
|
class AIConfig:
|
|
api_key: str
|
|
model: str
|
|
base_url: str
|
|
|
|
|
|
@dataclass
|
|
class TelegramConfig:
|
|
bot_token: str
|
|
chat_id: str
|
|
|
|
|
|
@dataclass
|
|
class PollingConfig:
|
|
interval_seconds: int
|
|
|
|
|
|
@dataclass
|
|
class Config:
|
|
email_accounts: List[EmailAccount]
|
|
ai: AIConfig
|
|
telegram: TelegramConfig
|
|
polling: PollingConfig
|
|
|
|
|
|
def load_config(path: str) -> Config:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
raw = yaml.safe_load(f)
|
|
|
|
accounts = []
|
|
for a in raw["email_accounts"]:
|
|
if "smtp" in a and a["smtp"] is not None:
|
|
a["smtp"] = SmtpConfig(**a["smtp"])
|
|
accounts.append(EmailAccount(**a))
|
|
ai = AIConfig(**raw["ai"])
|
|
tg = TelegramConfig(**raw["telegram"])
|
|
polling = PollingConfig(**raw["polling"])
|
|
|
|
return Config(
|
|
email_accounts=accounts,
|
|
ai=ai,
|
|
telegram=tg,
|
|
polling=polling,
|
|
)
|