utils.py 765 B

1234567891011121314151617181920212223242526272829
  1. # utils.py
  2. import asyncio
  3. from pathlib import Path
  4. from typing import List
  5. from aiopath import AsyncPath
  6. import logging
  7. # 把 1step.py 的主逻辑封装成函数
  8. from step1 import main as step1_main
  9. from step2 import main as step2_main
  10. log = logging.getLogger("utils")
  11. async def run_step1(proxy: str | None = None) -> str:
  12. try:
  13. await step1_main(proxy)
  14. return "画廊链接抓取完成!"
  15. except Exception as e:
  16. log.exception("step1 执行失败")
  17. return f"抓取失败:{e}"
  18. async def run_step2(proxy: str | None = None) -> str:
  19. try:
  20. await step2_main(proxy)
  21. return "图片下载完成!"
  22. except Exception as e:
  23. log.exception("step2 执行失败")
  24. return f"下载失败:{e}"