Files
2026-04-22 10:04:59 +02:00

44 lines
1.3 KiB
Python

#!/usr/bin/env python3
from __future__ import annotations
import os
from dataclasses import dataclass
from pathlib import Path
def load_dotenv(path: str = ".env") -> None:
dotenv_path = Path(path)
if not dotenv_path.exists():
return
for raw_line in dotenv_path.read_text(encoding="utf-8").splitlines():
line = raw_line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
key = key.strip()
value = value.strip().strip('"').strip("'")
if key and key not in os.environ:
os.environ[key] = value
@dataclass(frozen=True)
class AppSettings:
discord_bot_token: str
discord_guild_id: str
locale: str
animeschedule_api_token: str
tmdb_read_access_token: str
def get_settings() -> AppSettings:
load_dotenv()
return AppSettings(
discord_bot_token=os.environ.get("DISCORD_BOT_TOKEN", "").strip(),
discord_guild_id=os.environ.get("DISCORD_GUILD_ID", "").strip(),
locale=os.environ.get("LOCALE", "de-DE").strip() or "de-DE",
animeschedule_api_token=os.environ.get("ANIMESCHEDULE_API_TOKEN", "").strip(),
tmdb_read_access_token=os.environ.get("TMDB_READ_ACCESS_TOKEN", "").strip(),
)