init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from dataclasses import dataclass
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Config:
|
||||
bot_token: str
|
||||
allowed_user_ids: set[int]
|
||||
vault_path: Path
|
||||
daily_notes_dir: str
|
||||
note_path_format: str
|
||||
message_time_format: str
|
||||
telegram_proxy: str | None
|
||||
reminder_min_seconds: int
|
||||
reminder_max_seconds: int
|
||||
|
||||
|
||||
def _required(name: str) -> str:
|
||||
value = getenv(name)
|
||||
if not value:
|
||||
raise RuntimeError(f"Не задана переменная окружения {name}")
|
||||
return value
|
||||
|
||||
|
||||
def _user_ids(value: str) -> set[int]:
|
||||
return {int(user_id.strip()) for user_id in value.split(",") if user_id.strip()}
|
||||
|
||||
|
||||
def _hours_to_seconds(value: str) -> int:
|
||||
return int(float(value) * 60 * 60)
|
||||
# return int(float(value))
|
||||
|
||||
|
||||
def load_config() -> Config:
|
||||
return Config(
|
||||
bot_token=_required("BOT_TOKEN"),
|
||||
allowed_user_ids=_user_ids(_required("ALLOWED_USER_IDS")),
|
||||
vault_path=Path(_required("OBSIDIAN_VAULT_PATH")).expanduser().resolve(),
|
||||
daily_notes_dir=getenv("DAILY_NOTES_DIR", "03 Journal"),
|
||||
note_path_format=getenv("NOTE_PATH_FORMAT", "%Y/%m/%d.%m.%y.md"),
|
||||
message_time_format=getenv("MESSAGE_TIME_FORMAT", "%H:%M"),
|
||||
telegram_proxy=getenv("TELEGRAM_PROXY"),
|
||||
reminder_min_seconds=_hours_to_seconds(getenv("REMINDER_MIN_HOURS", "2")),
|
||||
reminder_max_seconds=_hours_to_seconds(getenv("REMINDER_MAX_HOURS", "3")),
|
||||
)
|
||||
Reference in New Issue
Block a user