#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Screen2Feishu 安装和设置脚本 """ import os import sys import subprocess import shutil from pathlib import Path def print_header(text): """打印标题""" print("\n" + "=" * 60) print(f" {text}") print("=" * 60) def print_step(text): """打印步骤""" print(f"\n▶ {text}") def check_python_version(): """检查Python版本""" print_step("检查Python版本...") version = sys.version_info if version.major < 3 or (version.major == 3 and version.minor < 8): print(f" Python版本过低: {sys.version}") print("请使用 Python 3.8 或更高版本") return False print(f" Python版本: {sys.version}") return True def install_dependencies(): """安装依赖""" print_step("安装依赖...") try: # 检查是否已安装pip subprocess.run([sys.executable, "-m", "pip", "--version"], check=True, capture_output=True) # 安装依赖 print("正在安装核心依赖...") subprocess.run([ sys.executable, "-m", "pip", "install", "-r", "requirements.txt" ], check=True) print(" 依赖安装完成") return True except subprocess.CalledProcessError as e: print(f" 依赖安装失败: {e}") return False except Exception as e: print(f" 发生错误: {e}") return False def create_directories(): """创建必要的目录""" print_step("创建目录...") directories = [ "monitor_images", "processed_images", "logs" ] for directory in directories: path = Path(directory) if not path.exists(): path.mkdir(exist_ok=True) print(f" 创建目录: {directory}") else: print(f"ℹ️ 目录已存在: {directory}") return True def create_config(): """创建配置文件""" print_step("创建配置文件...") config_path = Path("config.yaml") example_path = Path("config.example.yaml") if config_path.exists(): print("ℹ️ 配置文件已存在,跳过创建") return True if not example_path.exists(): print(" 示例配置文件不存在") return False # 复制示例配置文件 shutil.copy(example_path, config_path) print(" 已创建 config.yaml,请根据需要编辑配置") # 显示配置说明 print("\n📝 配置说明:") print("1. 编辑 config.yaml 文件") print("2. 填入你的 AI API Key") print("3. 填入你的飞书应用信息:") print(" - app_id") print(" - app_secret") print(" - app_token") print(" - table_id") print("4. 根据需要调整其他配置") return True def show_usage(): """显示使用说明""" print_step("使用说明:") print(""" 1. 配置文件: - 编辑 config.yaml,填入你的 API Key 和飞书信息 2. 启动程序: python main.py 3. 测试模式: python main.py --test 4. 查看帮助: python main.py --help 5. 运行测试: python -m unittest discover tests 6. 查看文档: - README.md - 项目说明 - docs/OPTIMIZED_R&D.md - 开发文档 - docs/PROJECT_IMPROVEMENT_PLAN.md - 改进计划 """) def main(): """主函数""" print_header("Screen2Feishu 安装向导") print("欢迎使用 Screen2Feishu 安装向导!") print("本脚本将帮助你完成以下步骤:") print("1. 检查Python版本") print("2. 安装依赖") print("3. 创建必要的目录") print("4. 创建配置文件") # 询问用户是否继续 response = input("\n是否继续? (y/n): ").strip().lower() if response not in ['y', 'yes']: print("安装已取消") return # 执行安装步骤 steps = [ ("检查Python版本", check_python_version), ("安装依赖", install_dependencies), ("创建目录", create_directories), ("创建配置文件", create_config), ] all_success = True for step_name, step_func in steps: print_header(step_name) if not step_func(): print(f" {step_name} 失败") all_success = False break if all_success: print_header("安装完成!") print(" 所有步骤完成!") show_usage() print("\n🎉 Screen2Feishu 安装成功!") print("请编辑 config.yaml 文件,然后运行: python main.py") else: print_header("安装失败") print(" 安装过程中出现问题,请检查错误信息并重试") if __name__ == "__main__": main()