39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent
|
|
|
|
|
|
def _load_dotenv() -> None:
|
|
env_path = PROJECT_ROOT / ".env"
|
|
if not env_path.exists():
|
|
return
|
|
for raw_line in env_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("'")
|
|
os.environ.setdefault(key, value)
|
|
|
|
|
|
def _parse_admins(value: str) -> list[int]:
|
|
if not value:
|
|
return []
|
|
return [int(part) for part in value.split(",") if part.strip().isdigit()]
|
|
|
|
|
|
_load_dotenv()
|
|
|
|
Token = os.getenv("VK_TOKEN", "")
|
|
SYNC_ADMINS = _parse_admins(os.getenv("SYNC_ADMINS", ""))
|
|
|
|
_credentials_file = Path(os.getenv("GOOGLE_CREDENTIALS_FILE", "creds.json"))
|
|
CREDENTIALS_FILE = str(_credentials_file if _credentials_file.is_absolute() else PROJECT_ROOT / _credentials_file)
|
|
SPREADSHEET_ID = os.getenv("GOOGLE_SPREADSHEET_ID", "")
|
|
LOG_SPREADSHEET_ID = os.getenv("LOG_SPREADSHEET_ID", "")
|
|
|
|
if not Token:
|
|
raise RuntimeError("VK_TOKEN is not set")
|