-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv.py
More file actions
25 lines (19 loc) · 784 Bytes
/
env.py
File metadata and controls
25 lines (19 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __future__ import annotations
from pathlib import Path
import os
PROJECT_ROOT = Path(__file__).resolve().parents[1]
ENV_PATH = PROJECT_ROOT / ".env"
STATE_PATH = PROJECT_ROOT / "state.json"
def load_env() -> dict:
values: dict[str, str] = {}
if ENV_PATH.exists():
for line in ENV_PATH.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
values[key.strip()] = value.strip().strip('"').strip("'")
for key, value in os.environ.items():
if key in values or key.startswith(("OAUTH_", "XCHAT_", "XDK_")) or key == "BEARER_TOKEN":
values[key] = value
return values