test_feishu_import.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. """
  3. 测试飞书导入功能
  4. 用法:
  5. python test_feishu_import.py [xlsx_path]
  6. 如果不提供路径,自动使用 outputs/reports/ 下最新的 xlsx
  7. """
  8. import asyncio
  9. import sys
  10. from pathlib import Path
  11. # 添加项目路径
  12. _MINI_DIR = Path(__file__).resolve().parent
  13. sys.path.insert(0, str(_MINI_DIR))
  14. from tools.feishu_doc import import_to_feishu
  15. async def main():
  16. xlsx_path = sys.argv[1] if len(sys.argv) > 1 else ""
  17. print(f"开始导入到飞书...")
  18. print(f"文件路径: {xlsx_path or '自动检测最新 xlsx'}")
  19. print("-" * 60)
  20. result = await import_to_feishu(
  21. ctx=None, # type: ignore
  22. xlsx_path=xlsx_path,
  23. send_im=True, # 发送到飞书群
  24. chat_id="", # 使用配置中的默认群
  25. )
  26. print("\n" + "=" * 60)
  27. print(f"标题: {result.title}")
  28. print("=" * 60)
  29. print(result.output)
  30. print("=" * 60)
  31. if result.metadata:
  32. print("\n详细信息:")
  33. for k, v in result.metadata.items():
  34. print(f" {k}: {v}")
  35. if __name__ == "__main__":
  36. asyncio.run(main())