#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 主程序入口 负责初始化和运行内容生成流程 """ import argparse import logging import time from datetime import datetime import asyncio from utils.pipeline import PipelineManager from core.exception import TravelContentCreatorError def setup_logging(): """配置日志记录""" logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S' ) # 可以为特定模块设置不同的日志级别 logging.getLogger("core.ai.AIAgent").setLevel(logging.DEBUG) async def main(): """主函数""" parser = argparse.ArgumentParser( description="运行内容生成流程", formatter_class=argparse.ArgumentDefaultsHelpFormatter ) parser.add_argument( "--config_dir", type=str, default="config", help="包含配置文件的目录路径" ) parser.add_argument( "--run_id", type=str, default=f"run_{datetime.now().strftime('%Y%m%d_%H%M%S')}", help="为本次运行指定一个唯一的ID" ) args = parser.parse_args() start_time = time.time() setup_logging() logging.info(f"--- 开始运行 --- Run ID: {args.run_id} ---") logging.info(f"使用配置目录: {args.config_dir}") try: pipeline = PipelineManager(config_dir=args.config_dir, run_id=args.run_id) await pipeline.run_pipeline() except TravelContentCreatorError as e: logging.critical(f"流程发生严重错误: {e}", exc_info=True) except Exception as e: logging.critical(f"发生未知异常: {e}", exc_info=True) finally: end_time = time.time() logging.info(f"--- 运行结束 --- 耗时: {end_time - start_time:.2f} 秒 ---") if __name__ == '__main__': asyncio.run(main())