run.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/4/25
  4. import datetime
  5. import os
  6. import random
  7. import sys
  8. import time
  9. sys.path.append(os.getcwd())
  10. from main.common import Common
  11. from main.download import BSZF
  12. class Main:
  13. @classmethod
  14. def download_job_dev(cls):
  15. """
  16. 测试环境脚本
  17. """
  18. Common.crawler_log().info("开始抓取本山祝福视频\n")
  19. BSZF.get_recommend()
  20. BSZF.download_video("dev")
  21. # 删除多余日志
  22. Common.del_logs()
  23. # 统计累计下载数量
  24. Common.benshanzhufu_download_count()
  25. @classmethod
  26. def download_job_prod(cls):
  27. """
  28. 正式环境脚本
  29. """
  30. while True:
  31. prod_time = datetime.datetime.now()
  32. if prod_time.hour < 15 or prod_time.hour > 19:
  33. Common.crawler_log().info("结束抓取视频\n")
  34. time.sleep(3)
  35. break
  36. else:
  37. BSZF.get_recommend()
  38. BSZF.download_video("prod")
  39. time.sleep(random.randint(1, 3))
  40. # 删除多余日志
  41. Common.del_logs()
  42. # 统计累计下载数量
  43. Common.benshanzhufu_download_count()
  44. @classmethod
  45. def main(cls):
  46. while True:
  47. while True:
  48. main_time = datetime.datetime.now()
  49. if 19 >= main_time.hour >= 15:
  50. Common.crawler_log().info("开始抓取本山祝福视频\n")
  51. cls.download_job_prod()
  52. else:
  53. time.sleep(600)
  54. break
  55. if __name__ == "__main__":
  56. main = Main()
  57. main.main()