commit 24a275d0667d7875b011c0606e3697397f1551e5 Author: Moonlit Jolteon Date: Thu Mar 13 10:13:27 2025 -0400 Basic file structure started with a couple utility classes diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cffcb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..e69de29 diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..60a6c0c --- /dev/null +++ b/config.json.example @@ -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" +} \ No newline at end of file diff --git a/utils/config_manager.py b/utils/config_manager.py new file mode 100644 index 0000000..69f7196 --- /dev/null +++ b/utils/config_manager.py @@ -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() diff --git a/utils/logger.py b/utils/logger.py new file mode 100644 index 0000000..36bedcd --- /dev/null +++ b/utils/logger.py @@ -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)