From af048b9333b8d35775fdccf0f1742e485be7b27e Mon Sep 17 00:00:00 2001 From: "Max P." Date: Mon, 24 Mar 2025 14:14:57 +0100 Subject: [PATCH] Adds configuration file reader utility Introduces a function to read and parse configuration settings from a JSON file. Handles errors gracefully with exception handling to ensure reliability. Facilitates centralized management of configuration settings. --- configuration.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 configuration.py diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000..e77f77d --- /dev/null +++ b/configuration.py @@ -0,0 +1,24 @@ + +import json +import os + +def read_configurations(): + """ + Reads the configuration settings from a JSON file named 'pyvtt.settings.json' + located in the same directory as the script. + + Returns: + dict: The configuration settings loaded from the JSON file. + + Raises: + Exception: If there is an error reading or parsing the JSON file, + an exception is raised with the error details. + """ + script_dir = os.path.dirname(os.path.abspath(__file__)) + settings_path = os.path.join(script_dir, "pyvtt.settings.json") + try: + with open(settings_path) as f: + return json.load(f) + except Exception as e: + print(f"Error reading configurations: {e}") + raise Exception(f"Error reading configurations: {e}") \ No newline at end of file