mirror of
https://github.com/MoonlitJolteon/frc-stat-predictor.git
synced 2025-11-02 22:05:03 +00:00
Basic file structure started with a couple utility classes
This commit is contained in:
37
utils/config_manager.py
Normal file
37
utils/config_manager.py
Normal 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()
|
||||
Reference in New Issue
Block a user