From a184eb430ce45fef858ab46dc758f911a3a80dbb Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 17 Nov 2023 12:52:41 +0000 Subject: [PATCH] Read config from home directory --- social_photos/load_config.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/social_photos/load_config.py b/social_photos/load_config.py index 9f1a3f3..aefb581 100644 --- a/social_photos/load_config.py +++ b/social_photos/load_config.py @@ -1,6 +1,34 @@ -import os, toml +import os +import toml + +def load_config(): + # Get the user's home directory + home_dir = os.path.expanduser("~") + + # Define the path to the config file + config_path = os.path.join(home_dir, ".conf", "social-photos", "conf.toml") + + # Check if the config file exists + if not os.path.exists(config_path): + print(f"Config file not found at {config_path}") + return None + + # Load and parse the config file + try: + with open(config_path, 'r') as config_file: + config_data = toml.load(config_file) + return config_data + except Exception as e: + print(f"Error loading config file: {e}") + return None + +# Example usage +config = load_config() +if config: + print("Config loaded successfully:", config) +else: + print("Failed to load config.") -config = toml.load("conf.toml") """ TOML FILE EXAMPLE: