forked from imvickykumar999/Insta-Loop-Live
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_loader.py
More file actions
28 lines (23 loc) · 846 Bytes
/
env_loader.py
File metadata and controls
28 lines (23 loc) · 846 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
25
26
27
28
"""Load .env from project root (local dev and fallback for workers)."""
import os
from pathlib import Path
_LOADED = False
def load_env() -> None:
global _LOADED
if _LOADED:
return
env_path = Path(__file__).resolve().parent / ".env"
if env_path.is_file():
try:
from dotenv import load_dotenv
load_dotenv(env_path, override=False)
except ImportError:
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.partition("=")
key = key.strip()
value = value.strip().strip('"').strip("'")
os.environ.setdefault(key, value)
_LOADED = True