main.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. import sys
  3. import threading
  4. import schedule
  5. import time
  6. import functools
  7. sys.path.append(os.getcwd())
  8. from common.db import MysqlHelper
  9. from video_capture.douyin.douyin_author.douyin_author import douyinAuthor
  10. from video_stitching.video_stitching import VideoStitching
  11. from datetime import datetime, timedelta
  12. def get_count():
  13. current_time = datetime.now()
  14. previous_time = current_time - timedelta(minutes=10)
  15. previous_time_str = previous_time.strftime("%Y-%m-%d %H:%M")
  16. select_user_sql = f"""select video_id from video_url where time >="{previous_time_str}";"""
  17. count = MysqlHelper.get_values(select_user_sql, "prod")
  18. if count:
  19. return True
  20. else:
  21. return False
  22. def check_token():
  23. while True:
  24. count = get_count()
  25. if count:
  26. time.sleep(1200) # 每20分钟检查一次
  27. else:
  28. douyinAuthor.get_token()
  29. # 创建并启动线程
  30. token_thread = threading.Thread(target=check_token)
  31. token_thread.start()
  32. # 每天下午4点定时启动 video_stitching 方法
  33. schedule.every().day.at("16:00").do(functools.partial(VideoStitching.video_stitching))
  34. while True:
  35. schedule.run_pending()
  36. time.sleep(1)