Medisync / utils /config_loader.py
anique-1's picture
Deploy MediSync AI Backend with APK to Hugging Face
903c699
Raw
History Blame Contribute Delete
1.19 kB
import os
import json
from dotenv import load_dotenv
load_dotenv()
SETTINGS_FILE = "settings.json"
def load_settings_from_file():
if not os.path.exists(SETTINGS_FILE):
return {}
try:
with open(SETTINGS_FILE, "r") as f:
return json.load(f)
except Exception as e:
print(f"Error loading settings file: {e}")
return {}
def save_settings_to_file(settings):
try:
current_settings = load_settings_from_file()
current_settings.update(settings)
with open(SETTINGS_FILE, "w") as f:
json.dump(current_settings, f, indent=4)
return True
except Exception as e:
print(f"Error saving settings file: {e}")
return False
def get_setting(key, default=None):
# 1. Check file settings
file_settings = load_settings_from_file()
if key in file_settings and file_settings[key]:
return file_settings[key]
# 2. Check environment variables
# We reload dotenv to check if .env has changed (though usually requires restart)
# create_ref: but os.environ is what matters.
val = os.getenv(key)
if val:
return val
return default