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

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.json

0
app.py Normal file
View File

5
config.json.example Normal file
View File

@ -0,0 +1,5 @@
{
"TBA_TOKEN": "Get your read API token here: https://www.thebluealliance.com/account",
"USE_ISA_DATA": false,
"ISA_TOKEN": "If you are a member of the Indiana Scouting Alliance, put your token here. Reach out to the discord if you don't know how to get it"
}

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()

55
utils/logger.py Normal file
View File

@ -0,0 +1,55 @@
import logging
import os
from datetime import datetime
class Logger:
"""Handles logging for the application"""
def __init__(self, log_dir="logs", log_level=logging.INFO):
self.log_dir = log_dir
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = os.path.join(
log_dir, f"frcsp_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
)
self.logger = logging.getLogger("frcsp")
self.logger.setLevel(log_level)
# File handler
file_handler = logging.FileHandler(log_file)
file_handler.setLevel(log_level)
# Console handler
console_handler = logging.StreamHandler()
console_handler.setLevel(log_level)
# Formatter
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)
# Add handlers
self.logger.addHandler(file_handler)
self.logger.addHandler(console_handler)
def info(self, message):
"""Log an info message"""
self.logger.info(message)
def warning(self, message):
"""Log a warning message"""
self.logger.warning(message)
def error(self, message):
"""Log an error message"""
self.logger.error(message)
def debug(self, message):
"""Log a debug message"""
self.logger.debug(message)