run.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if len(BSZF.download_video_list) >= 10:
  19. Common.crawler_log().info("已下载视频数:{}".format(len(BSZF.download_video_list)))
  20. else:
  21. Common.crawler_log().info("开始抓取本山祝福视频\n")
  22. BSZF.get_recommend()
  23. BSZF.download_video("dev")
  24. # 删除多余日志
  25. Common.del_logs()
  26. # 统计累计下载数量
  27. Common.benshanzhufu_download_count()
  28. @classmethod
  29. def main_dev(cls):
  30. while True:
  31. main_dev_time = datetime.datetime.now()
  32. if main_dev_time.hour >= 15:
  33. cls.download_job_dev()
  34. else:
  35. break
  36. @classmethod
  37. def download_job_prod(cls):
  38. """
  39. 正式环境脚本
  40. """
  41. while True:
  42. prod_time = datetime.datetime.now()
  43. if prod_time.hour < 15 or prod_time.hour > 19:
  44. Common.crawler_log().info("结束抓取视频\n")
  45. time.sleep(3)
  46. break
  47. else:
  48. BSZF.get_recommend()
  49. BSZF.download_video("prod")
  50. time.sleep(random.randint(1, 3))
  51. # 删除多余日志
  52. Common.del_logs()
  53. # 统计累计下载数量
  54. Common.benshanzhufu_download_count()
  55. @classmethod
  56. def main(cls):
  57. while True:
  58. while True:
  59. main_time = datetime.datetime.now()
  60. if 19 >= main_time.hour >= 15:
  61. Common.crawler_log().info("开始抓取本山祝福视频\n")
  62. cls.download_job_prod()
  63. else:
  64. time.sleep(600)
  65. break
  66. if __name__ == "__main__":
  67. main = Main()
  68. # main.main()
  69. main.main_dev()