Basic file structure started with a couple utility classes

This commit is contained in:
2025-03-13 10:13:27 -04:00
commit 24a275d066
5 changed files with 98 additions and 0 deletions

37
utils/config_manager.py Normal file
View File

@ -0,0 +1,37 @@
import json
import os
class ConfigurationManager:
"""Manages configuration settings for the application"""
def __init__(self, config_file="config.json"):
self.__config_file = config_file
self.__config = {}
self.load_config()
def load_config(self):
"""Load configuration from file"""
if os.path.exists(self.__config_file):
try:
with open(self.__config_file, "r") as f:
self.__config = json.load(f)
except Exception as e:
print(f"Error loading configuration: {e}")
def save_config(self):
"""Save configuration to file"""
try:
with open(self.__config_file, "w") as f:
json.dump(self.__config, f, indent=4)
except Exception as e:
print(f"Error saving configuration: {e}")
def get(self, key, default=None):
"""Get a configuration value"""
return self.__config.get(key, default)
def set(self, key, value):
"""Set a configuration value"""
self.__config[key] = value
self.save_config()