job_keyword_dy.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import time
  2. import schedule
  3. from common import Material
  4. from common.sql_help import sqlCollect
  5. from video_rewriting.video_processor import VideoProcessor
  6. def video_task_start():
  7. """抖视频搜索处理视频任务,返回用户名并根据结果决定延迟时间"""
  8. data = Material.feishu_list()[14]
  9. while True:
  10. try:
  11. count = sqlCollect.get_channel_count("抖音搜索", "品类关键词搜索")
  12. count = int(count[0][0])
  13. sheet_count = Material.get_count_restrict("抖音关键词搜索")
  14. if sheet_count:
  15. if count >= int(sheet_count):
  16. print(f"到了限制数{count}")
  17. return
  18. print("开始执行任务")
  19. mark = VideoProcessor.main(data)
  20. print(f"返回用户名: {mark}")
  21. # time.sleep(10 if mark else 120) # 根据 mark 是否为空设置延迟
  22. except Exception as e:
  23. print("处理任务时出现异常:", e)
  24. time.sleep(10)
  25. continue
  26. def schedule_tasks():
  27. schedule.every(10).minutes.do(video_task_start)
  28. if __name__ == '__main__':
  29. schedule_tasks() # 调用任务调度函数
  30. while True:
  31. schedule.run_pending()
  32. time.sleep(1) # 每秒钟检查一次