update_materials.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. """
  3. 自动化更新脚本 - 素材库全量更新流水线
  4. 功能: 从原始PDF报告更新素材库的三个核心数据文件
  5. 流程:
  6. 1. 分类重命名报告 (process_all_pdfs.py)
  7. 2. 全类型数据提取 (extract_all_types.py)
  8. 3. 全类型学生合并 (merge_all_types.py)
  9. 4. 删除重复A1报告 (delete_duplicate_a1.py)
  10. 用法:
  11. python scripts/reports/update_materials.py # 从 scripts 目录运行
  12. cd 项目根目录 && python scripts/reports/update_materials.py # 从根目录运行
  13. """
  14. import os
  15. import sys
  16. import subprocess
  17. # 脚本所在目录 = scripts/reports/
  18. SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
  19. PROJECT_DIR = os.path.dirname(os.path.dirname(SCRIPTS_DIR))
  20. def run_script(script_name, label):
  21. """运行 scripts/reports/ 中的脚本"""
  22. script_path = os.path.join(SCRIPTS_DIR, script_name)
  23. print(f"\n{'=' * 50}")
  24. print(f"[{label}] 运行: {script_name}")
  25. print(f"{'=' * 50}")
  26. result = subprocess.run(
  27. [sys.executable, script_path],
  28. cwd=PROJECT_DIR,
  29. capture_output=False
  30. )
  31. if result.returncode != 0:
  32. print(f" [FAIL] [{label}] 失败 (exit code={result.returncode})")
  33. return False
  34. print(f" [OK] [{label}] 完成")
  35. return True
  36. def main():
  37. print("=" * 60)
  38. print(" 素材库全量更新流水线")
  39. print("=" * 60)
  40. print(f" 项目根目录: {PROJECT_DIR}")
  41. print(f" 脚本目录: {SCRIPTS_DIR}")
  42. steps = [
  43. ("process_all_pdfs.py", "1/4 报告分类重命名"),
  44. ("extract_all_types.py", "2/4 全类型数据提取"),
  45. ("merge_all_types.py", "3/4 全类型学生合并"),
  46. ("delete_duplicate_a1.py", "4/4 清理重复A1报告"),
  47. ]
  48. for script, label in steps:
  49. if not run_script(script, label):
  50. print(f"\n ❌ 流水线在 [{label}] 中断")
  51. sys.exit(1)
  52. print(f"\n{'=' * 60}")
  53. print(" [OK] 素材库更新完成!")
  54. print(f"{'=' * 60}")
  55. print("\n生成的文件:")
  56. print(" - 素材库/测评数据_优化提取.csv")
  57. print(" - 素材库/学生汇总数据.csv")
  58. print("\n提示: 案例库.md 需要手动根据新增数据更新案例")
  59. if __name__ == "__main__":
  60. main()