Ver código fonte

update download time and cnt

wangkun 3 anos atrás
pai
commit
a3b56ba8c5
2 arquivos alterados com 25 adições e 29 exclusões
  1. 8 8
      main/download.py
  2. 17 21
      main/run.py

+ 8 - 8
main/download.py

@@ -287,23 +287,23 @@ class BSZF:
 
                     # 删除该视频在benshanzhufu_feeds.txt中的信息
                     Common.crawler_log().info("删除该视频在benshanzhufu_feeds.txt中的信息:{}".format(download_video_title))
-                    with open(r"./txt/benshanzhufu_feeds.txt", "r", encoding="UTF-8") as f_r:
-                        lines = f_r.readlines()
-                    with open(r"./txt/benshanzhufu_feeds.txt", "w", encoding="utf-8") as f_w:
+                    with open(r"./txt/benshanzhufu_feeds.txt", "r", encoding="UTF-8") as f_r3:
+                        lines = f_r3.readlines()
+                    with open(r"./txt/benshanzhufu_feeds.txt", "w", encoding="utf-8") as f_w3:
                         for line in lines:
                             if download_video_id in line.split(" + ")[1]:
                                 continue
-                            f_w.write(line)
+                            f_w3.write(line)
             except Exception as e:
                 # 删除该视频在 recommend.txt中的信息
                 Common.crawler_log().error("该视频信息异常,删除在benshanzhufu_feeds.txt中的信息:{}".format(e))
-                with open(r"./txt/benshanzhufu_feeds.txt", "r", encoding="UTF-8") as f_r:
-                    lines = f_r.readlines()
-                with open(r"./txt/benshanzhufu_feeds.txt", "w", encoding="utf-8") as f_w:
+                with open(r"./txt/benshanzhufu_feeds.txt", "r", encoding="UTF-8") as f_r4:
+                    lines = f_r4.readlines()
+                with open(r"./txt/benshanzhufu_feeds.txt", "w", encoding="utf-8") as f_w4:
                     for line in lines:
                         if download_video_id in line.split(" + ")[1]:
                             continue
-                        f_w.write(line)
+                        f_w4.write(line)
 
 
 if __name__ == "__main__":

+ 17 - 21
main/run.py

@@ -3,7 +3,6 @@
 # @Time: 2022/4/25
 import datetime
 import os
-import random
 import sys
 import time
 sys.path.append(os.getcwd())
@@ -19,6 +18,7 @@ class Main:
         """
         if len(BSZF.download_video_list) >= 10:
             Common.crawler_log().info("已下载视频数:{}".format(len(BSZF.download_video_list)))
+            time.sleep(1800)
         else:
             Common.crawler_log().info("开始抓取本山祝福视频\n")
             BSZF.get_recommend()
@@ -32,27 +32,25 @@ class Main:
     @classmethod
     def main_dev(cls):
         while True:
-            main_dev_time = datetime.datetime.now()
-            if main_dev_time.hour >= 15:
-                cls.download_job_dev()
-            else:
-                break
+            while True:
+                main_dev_time = datetime.datetime.now()
+                if main_dev_time.hour >= 15:
+                    cls.download_job_dev()
+                else:
+                    break
 
     @classmethod
     def download_job_prod(cls):
         """
         正式环境脚本
         """
-        while True:
-            prod_time = datetime.datetime.now()
-            if prod_time.hour < 15 or prod_time.hour > 19:
-                Common.crawler_log().info("结束抓取视频\n")
-                time.sleep(3)
-                break
-            else:
-                BSZF.get_recommend()
-                BSZF.download_video("prod")
-                time.sleep(random.randint(1, 3))
+        if len(BSZF.download_video_list) >= 300:
+            Common.crawler_log().info("已下载视频数:{}".format(len(BSZF.download_video_list)))
+            time.sleep(1800)
+        else:
+            Common.crawler_log().info("开始抓取本山祝福视频\n")
+            BSZF.get_recommend()
+            BSZF.download_video("prod")
 
         # 删除多余日志
         Common.del_logs()
@@ -64,15 +62,13 @@ class Main:
         while True:
             while True:
                 main_time = datetime.datetime.now()
-                if 19 >= main_time.hour >= 15:
-                    Common.crawler_log().info("开始抓取本山祝福视频\n")
+                if main_time.hour >= 15:
                     cls.download_job_prod()
                 else:
-                    time.sleep(600)
                     break
 
 
 if __name__ == "__main__":
     main = Main()
-    # main.main()
-    main.main_dev()
+    main.main()
+    # main.main_dev()