from __future__ import annotations import os from dataclasses import dataclass from typing import Optional @dataclass class Settings: telegram_token: str boinc_host: str = "localhost" boinc_port: int = 31416 boinc_password: Optional[str] = None boinccmd_path: str = "boinccmd" sample_output: Optional[str] = None refresh_seconds: int = 30 @classmethod def from_env(cls) -> "Settings": token = os.getenv("TELEGRAM_TOKEN") or os.getenv("BOT_TOKEN") if not token: raise ValueError("Set TELEGRAM_TOKEN (or BOT_TOKEN) in the environment") host = os.getenv("BOINC_HOST", "localhost") port = int(os.getenv("BOINC_PORT", "31416")) password = os.getenv("BOINC_PASSWORD") boinccmd_path = os.getenv("BOINC_CMD", "boinccmd") sample_output = os.getenv("BOINC_SAMPLE_FILE") refresh_seconds = int(os.getenv("REFRESH_SECONDS", "30")) return cls( telegram_token=token, boinc_host=host, boinc_port=port, boinc_password=password, boinccmd_path=boinccmd_path, sample_output=sample_output, refresh_seconds=refresh_seconds, )