diff --git a/main.py b/main.py index cc26ea3..d7812fc 100644 --- a/main.py +++ b/main.py @@ -30,8 +30,8 @@ from utils.poster_notes_creator import select_additional_images def load_config(config_path="poster_gen_config.json"): """Loads configuration from a JSON file.""" if not os.path.exists(config_path): - print(f"Error: Configuration file '{config_path}' not found.") - print("Please copy 'example_config.json' to 'poster_gen_config.json' and customize it.") + logging.error(f"Error: Configuration file '{config_path}' not found.") + logging.info("Please copy 'example_config.json' to 'poster_gen_config.json' and customize it.") sys.exit(1) try: with open(config_path, 'r', encoding='utf-8') as f: @@ -40,23 +40,23 @@ def load_config(config_path="poster_gen_config.json"): required_keys = ["api_url", "model", "api_key", "resource_dir", "output_dir", "num", "variants", "topic_system_prompt", "topic_user_prompt", "content_system_prompt", "image_base_dir"] if not all(key in config for key in required_keys): missing_keys = [key for key in required_keys if key not in config] - print(f"Error: Config file '{config_path}' is missing required keys: {missing_keys}") + logging.error(f"Error: Config file '{config_path}' is missing required keys: {missing_keys}") sys.exit(1) # 验证prompts_dir或prompts_config至少有一个存在 if not ("prompts_dir" in config or "prompts_config" in config): - print(f"Error: Config file '{config_path}' must contain either 'prompts_dir' or 'prompts_config'") + logging.error(f"Error: Config file '{config_path}' must contain either 'prompts_dir' or 'prompts_config'") sys.exit(1) # Resolve relative paths based on config location or a defined base path if necessary # For simplicity, assuming paths in config are relative to project root or absolute return config except json.JSONDecodeError: - print(f"Error: Could not decode JSON from '{config_path}'. Check the file format.") + logging.error(f"Error: Could not decode JSON from '{config_path}'. Check the file format.") sys.exit(1) except Exception as e: - print(f"Error loading configuration from '{config_path}': {e}") + logging.error(f"Error loading configuration from '{config_path}': {e}") sys.exit(1) # Removed generate_topics_step function definition from here