from pathlib import Path
|
import yaml
|
|
|
class Settings:
|
secret_key: str = ''
|
sgb_base_url: str = ''
|
sgb_websocket_url: str = ''
|
fwr_base_url: str = ''
|
database_url: str = ''
|
sgb_db_url: str = ''
|
fwr_db_url: str = ''
|
fetch_sgb_agent: str = ''
|
fetch_fwr_agent: str = ''
|
PUBLIC_KEY: str
|
PRIVATE_KEY: str
|
HASH_SUB_KEY: str
|
|
def __init__(self, **kwargs):
|
# Check if all required fields are provided and set them
|
for field in self.__annotations__.keys():
|
if field not in kwargs:
|
raise ValueError(f"Missing setting: {field}")
|
setattr(self, field, kwargs[field])
|
|
def to_dict(self):
|
"""Return the settings as a dictionary."""
|
return {k: getattr(self, k) for k in self.__annotations__.keys()}
|
|
def __repr__(self):
|
"""Return a string representation of the settings."""
|
return f"Settings({self.to_dict()})"
|
|
|
def load_yaml(file_path: Path) -> dict:
|
with file_path.open('r', encoding="utf-8") as fr:
|
try:
|
data = yaml.safe_load(fr)
|
return data
|
except yaml.YAMLError as e:
|
print(f"Error loading YAML file {file_path}: {e}")
|
return {}
|
|
|
# Use pathlib to handle file paths
|
config_yaml_path = Path(__file__).parent / 'config.yaml'
|
settings_data = load_yaml(config_yaml_path)
|
|
# Initialize settings object
|
settings = Settings(**settings_data)
|
|
# Print the loaded settings
|
print(f"Loaded settings: {settings}")
|