-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_loader.py
More file actions
28 lines (20 loc) · 805 Bytes
/
Copy pathconfig_loader.py
File metadata and controls
28 lines (20 loc) · 805 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
"""
Central config loader. Both fetcher.py and app.py import CONFIG from here.
Resolves paths relative to the project folder so services work regardless of
NSSM's working directory.
"""
import os
import yaml
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
CONFIG_PATH = os.path.join(PROJECT_DIR, 'config.yaml')
def load_config():
if not os.path.exists(CONFIG_PATH):
raise FileNotFoundError(f"config.yaml not found at {CONFIG_PATH}")
with open(CONFIG_PATH, 'r', encoding='utf-8') as f:
cfg = yaml.safe_load(f)
# Resolve DB path absolutely
cfg['database']['path'] = os.path.join(PROJECT_DIR, cfg['database']['filename'])
# Convenience: meter lookup by id
cfg['meters_by_id'] = {m['id']: m for m in cfg['meters']}
return cfg
CONFIG = load_config()