from configparser import ConfigParser from pathlib import Path import platform class Config: _instance = None def __new__(cls): if cls._instance is None: cls._instance = super().__new__(cls) config = ConfigParser() config_path = Path("config.ini") config.read(config_path) cls._instance.config = config return cls._instance def get_mssql_url(self) -> str: mssql = self.config["mssql"] driver = "ODBC Driver 18 for SQL Server" if platform.platform.system() == "Linux" else "SQL Server" driver = driver.replace(" ", "+") return f"mssql+pyodbc://{mssql['user']}:{mssql['password']}@{mssql['host']}/{mssql['name']}?driver={driver}" def get_postgres_url(self) -> str: db = self.config["postgres"] return f"postgresql://{db['user']}:{db['password']}@{db['host']}/{db['name']}" def get_seq_url(self) -> str: seq = self.config["seq"] return seq["url"] def get_seq_api_key(self) -> str: seq = self.config["seq"] return seq["api_key"]