|
| 1 | +# config_loader.py |
| 2 | +# (update to include RateLimitSettings and NotificationSettings) |
| 3 | + |
| 4 | +import configparser |
| 5 | +import os |
| 6 | +import logging |
| 7 | + |
| 8 | +logger = logging.getLogger(__name__) |
| 9 | + |
| 10 | +class ConfigLoader: |
| 11 | + _instance = None |
| 12 | + _config = None |
| 13 | + |
| 14 | + def __new__(cls): |
| 15 | + if cls._instance is None: |
| 16 | + cls._instance = super(ConfigLoader, cls).__new__(cls) |
| 17 | + cls._config = configparser.ConfigParser() |
| 18 | + base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 19 | + config_path = os.path.join(base_dir, 'config', 'config.ini') |
| 20 | + |
| 21 | + if os.path.exists(config_path): |
| 22 | + cls._config.read(config_path) |
| 23 | + logger.info(f"Loaded config from {config_path}") |
| 24 | + for section in cls._config.sections(): |
| 25 | + logger.debug(f"Section [{section}]: {dict(cls._config[section])}") |
| 26 | + else: |
| 27 | + logger.warning(f"Config file not found at {config_path}") |
| 28 | + return cls._instance |
| 29 | + |
| 30 | + @classmethod |
| 31 | + def get_config(cls): |
| 32 | + if cls._config is None: |
| 33 | + cls() |
| 34 | + return cls._config |
| 35 | + |
| 36 | + # NEW: Method to get Notification Settings |
| 37 | + @classmethod |
| 38 | + def get_notification_settings(cls): |
| 39 | + config = cls.get_config() # Get the config object |
| 40 | + send_completion_message = config.getboolean('NotificationSettings', 'sendcompletionmessage', fallback=True) |
| 41 | + completion_message = config.get('NotificationSettings', 'completionmessage', fallback="Transcription complete. Have a nice day!") |
| 42 | + |
| 43 | + return { |
| 44 | + 'send_completion_message': send_completion_message, |
| 45 | + 'completion_message': completion_message |
| 46 | + } |
| 47 | + |
| 48 | +# Usage example: |
| 49 | +# from config_loader import ConfigLoader |
| 50 | +# notification_settings = ConfigLoader.get_notification_settings() |
0 commit comments