data-vault/scripts/helpers/misc.py

20 lines
542 B
Python
Raw Permalink Normal View History

2025-02-05 10:21:50 -05:00
import json
import os
from pathlib import Path
2025-02-26 18:53:06 -05:00
CONFIG_PATH = (os.environ.get("XDG_CONFIG_HOME") or (Path.home() / ".config")) / "data-vault" / "config.json"
2025-02-05 10:21:50 -05:00
def load_config():
"""Load configuration from config file."""
if CONFIG_PATH.exists():
config = json.loads(CONFIG_PATH.read_text())
else:
config = {}
2025-02-05 15:47:05 -05:00
return config
def json_default(obj):
"""Default JSON encoder for serializing datetime objects."""
if hasattr(obj, 'isoformat'):
return obj.isoformat()
return super().default(obj)