25 lines
657 B
Python
25 lines
657 B
Python
|
|
# ui/streamlit_app/utils.py
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
|
||
|
|
from src.db.database_manager import DatabaseManager
|
||
|
|
import yaml
|
||
|
|
|
||
|
|
def load_settings(path="config/settings.yml"):
|
||
|
|
with open(path, "r") as f:
|
||
|
|
return yaml.safe_load(f)
|
||
|
|
|
||
|
|
def save_settings(settings, path="config/settings.yml"):
|
||
|
|
with open(path, "w") as f:
|
||
|
|
yaml.dump(settings, f)
|
||
|
|
|
||
|
|
def get_db():
|
||
|
|
config = load_settings()
|
||
|
|
db_config = config.get("db", {
|
||
|
|
"host": "localhost",
|
||
|
|
"user": "root",
|
||
|
|
"password": "",
|
||
|
|
"database": "data"
|
||
|
|
})
|
||
|
|
return DatabaseManager(db_config)
|