job_keyword_dy.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. try:
  10. count = sqlCollect.get_channel_count("抖音搜索", "品类关键词搜索")
  11. count = int(count[0][0])
  12. sheet_count = Material.get_count_restrict("抖音关键词搜索")
  13. if sheet_count:
  14. if count >= int(sheet_count):
  15. print(f"到了限制数{count}")
  16. return
  17. print("开始执行任务")
  18. mark = VideoProcessor.main(data)
  19. print(f"返回用户名: {mark}")
  20. # time.sleep(10 if mark else 120) # 根据 mark 是否为空设置延迟
  21. except Exception as e:
  22. print("处理任务时出现异常:", e)
  23. time.sleep(10)
  24. return
  25. def schedule_tasks():
  26. schedule.every(10).minutes.do(video_task_start)
  27. if __name__ == '__main__':
  28. schedule_tasks() # 调用任务调度函数
  29. while True:
  30. schedule.run_pending()
  31. time.sleep(1) # 每秒钟检查一次