config.py 574 B

1234567891011121314151617181920212223242526
  1. """Local configuration helpers.
  2. Secrets are read from environment variables or local_config.json. The local
  3. config file is intentionally gitignored.
  4. """
  5. import json
  6. import os
  7. HERE = os.path.dirname(os.path.abspath(__file__))
  8. LOCAL_CONFIG_PATH = os.path.join(HERE, "local_config.json")
  9. def _local_config():
  10. try:
  11. with open(LOCAL_CONFIG_PATH, encoding="utf-8") as f:
  12. return json.load(f)
  13. except Exception:
  14. return {}
  15. _CONFIG = _local_config()
  16. def get(name, default=""):
  17. return os.environ.get(name) or _CONFIG.get(name) or default