agc_main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from common import Feishu, Material
  2. from common.sql_help import sqlHelp
  3. from video_agc.agc_video_method import AgcVidoe
  4. import schedule
  5. import threading
  6. import time
  7. # 记录今天已经返回的用户名
  8. returned_usernames_today = set()
  9. def video_start(user_data):
  10. global returned_usernames_today
  11. user_data_mark = user_data[0]["mark"]
  12. # 开始准备执行生成视频脚本
  13. if user_data_mark is not None and user_data_mark in returned_usernames_today:
  14. print(f"视频脚本参数中的用户名 {user_data_mark} 今天已经返回过,不再启动线程。")
  15. return # 如果返回了某个用户名,并且今天已经返回过,则不启动线程
  16. elif user_data_mark is not None:
  17. print(f"视频脚本参数{user_data}")
  18. mark = AgcVidoe.video_stitching(user_data)
  19. returned_usernames_today.add(mark)
  20. # 定义定时任务
  21. def video_task():
  22. print("开始执行生成视频脚.")
  23. data = Material.feishu_list()
  24. threads = []
  25. for _, user_data in data.iterrows():
  26. thread = threading.Thread(target=video_start, args=(user_data,))
  27. threads.append(thread)
  28. thread.start()
  29. for thread in threads:
  30. thread.join()
  31. print("执行生成视频脚结束")
  32. schedule.every(10).minutes.do(video_task)
  33. # 每天0点清空集合
  34. schedule.every().day.at("00:00").do(lambda: returned_usernames_today.clear())
  35. def job_feishu_bot():
  36. name_list = Material.feishu_name()
  37. count_list = sqlHelp.get_count_list(name_list)
  38. Feishu.bot('recommend', 'AGC视频', f'{"".join(count_list)}', 'all')
  39. print("机器人通知完成")
  40. # 每天下午1:30执行任务
  41. schedule.every().day.at("15:00").do(job_feishu_bot)
  42. while True:
  43. schedule.run_pending()
  44. time.sleep(1)
  45. # list = Material.feishu_list()
  46. # AgcVidoe.video_stitching(list)
  47. # print(list)