Refactor bot and integrate services
This commit is contained in:
24
config.py
Normal file
24
config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from typing import Dict
|
||||
import yaml
|
||||
|
||||
CONFIG_FILE = "/opt/tg-bot/config.yaml"
|
||||
|
||||
|
||||
def load_cfg(path: str = CONFIG_FILE) -> dict:
|
||||
with open(path) as f:
|
||||
return yaml.safe_load(f)
|
||||
|
||||
|
||||
def load_env(env_file: str) -> Dict[str, str]:
|
||||
env: Dict[str, str] = {}
|
||||
with open(env_file) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
if line.startswith("export "):
|
||||
line = line[len("export "):]
|
||||
if "=" in line:
|
||||
k, v = line.split("=", 1)
|
||||
env[k] = v.strip().strip('"')
|
||||
return env
|
||||
Reference in New Issue
Block a user