ソースを参照

update upload and push

wangkun 3 年 前
コミット
d6aede270d
2 ファイル変更15 行追加14 行削除
  1. 6 6
      main/download_weishi.py
  2. 9 8
      main/publish.py

+ 6 - 6
main/download_weishi.py

@@ -213,7 +213,7 @@ class Weishi:
                                     and video_duration != "0" and video_id != "0":
                                 basic_time = int(time.time())
                                 Common.crawler_log().info("添加视频信息至weishi_feeds.txt:{}".format(video_title))
-                                with open("./txt/weishi_feeds.txt", "a", encoding="UTF-8") as f_a:
+                                with open(r"./txt/weishi_feeds.txt", "a", encoding="UTF-8") as f_a:
                                     f_a.write(str(basic_time) + " + " +
                                               str(video_id) + " + " +
                                               str(video_play_cnt) + " + " +
@@ -239,7 +239,7 @@ class Weishi:
                                 else:
                                     basic_time = int(time.time())
                                     Common.crawler_log().info("添加视频信息至weishi_feeds.txt:{}".format(video_title))
-                                    with open("./txt/weishi_feeds.txt", "a", encoding="UTF-8") as f_a:
+                                    with open(r"./txt/weishi_feeds.txt", "a", encoding="UTF-8") as f_a:
                                         f_a.write(str(basic_time) + " + " +
                                                   str(video_id) + " + " +
                                                   str(video_play_cnt) + " + " +
@@ -322,9 +322,9 @@ class Weishi:
 
                 # 删除该视频在weishi_feeds.txt中的信息
                 Common.crawler_log().info("删除该视频在weishi_feeds.txt中的信息:{}".format(download_video_title))
-                with open("./txt/weishi_feeds.txt", "r", encoding="UTF-8") as f_r:
+                with open(r"./txt/weishi_feeds.txt", "r", encoding="UTF-8") as f_r:
                     lines = f_r.readlines()
-                with open("./txt/weishi_feeds.txt", "w", encoding="utf-8") as f_w:
+                with open(r"./txt/weishi_feeds.txt", "w", encoding="utf-8") as f_w:
                     for line in lines:
                         if download_video_id in line.split(" + ")[1]:
                             continue
@@ -332,9 +332,9 @@ class Weishi:
             else:
                 # 删除该视频在weishi_feeds.txt中的信息
                 Common.crawler_log().info("该视频不满足下载规则,删除在weishi_feeds.txt中的信息:{}".format(download_video_title))
-                with open("./txt/weishi_feeds.txt", "r", encoding="UTF-8") as f_r:
+                with open(r"./txt/weishi_feeds.txt", "r", encoding="UTF-8") as f_r:
                     lines = f_r.readlines()
-                with open("./txt/weishi_feeds.txt", "w", encoding="utf-8") as f_w:
+                with open(r"./txt/weishi_feeds.txt", "w", encoding="utf-8") as f_w:
                     for line in lines:
                         if download_video_id in line.split(" + ")[1]:
                             continue

+ 9 - 8
main/publish.py

@@ -115,30 +115,30 @@ class Publish:
     - 读取 基本信息 调用发布接口
     """
     # env 日期20220225 文件名
-    oss_file_path_video = 'longvideo/crawler_local/video/{}/{}/{}'
-    oss_file_path_image = 'longvideo/crawler_local/image/{}/{}/{}'
+    oss_file_path_video = r'longvideo/crawler_local/video/{}/{}/{}'
+    oss_file_path_image = r'longvideo/crawler_local/image/{}/{}/{}'
 
     @classmethod
     def put_file(cls, oss_file, local_file):
-        Common.crawler_log().info("put oss file = {}, local file = {}".format(oss_file, local_file))
+        # Common.crawler_log().info("put oss file = {}, local file = {}".format(oss_file, local_file))
         cls.bucket.put_object_from_file(oss_file, local_file)
         Common.crawler_log().info("put oss file = {}, local file = {} success".format(oss_file, local_file))
 
     # 清除本地文件
     @classmethod
     def remove_local_file(cls, local_file):
-        Common.crawler_log().info("remove local file = {}".format(local_file))
+        # Common.crawler_log().info("remove local file = {}".format(local_file))
         os.remove(local_file)
         Common.crawler_log().info("remove local file = {} success".format(local_file))
 
     # 清除本地文件夹
     @classmethod
     def remove_local_file_dir(cls, local_file):
-        Common.crawler_log().info("remove local file dir = {}".format(local_file))
+        # Common.crawler_log().info("remove local file dir = {}".format(local_file))
         os.rmdir(local_file)
         Common.crawler_log().info("remove local file dir = {} success".format(local_file))
 
-    local_file_path = './videos'
+    local_file_path = '.\\videos'
     video_file = 'video'
     image_file = 'image'
     info_file = 'info'
@@ -185,7 +185,7 @@ class Publish:
                     # 单个视频文件夹下的所有视频文件
                     for fi in dir_files:
                         # 视频文件夹下的所有文件路径
-                        fi_path = fi_d + '/' + fi
+                        fi_path = fi_d + '\\' + fi
                         Common.crawler_log().info('dir fi_path = {}'.format(fi_path))
                         # 读取 info.txt,赋值给 data
                         if cls.info_file in fi:
@@ -206,12 +206,13 @@ class Publish:
                                         data['crawlerSrcPublishTimestamp'] = line
                                 else:
                                     Common.crawler_log().warning("{} line is None".format(fi_path))
+                            f.close()
                             # remove info.txt
                             cls.remove_local_file(fi_path)
                     # 刷新数据
                     dir_files = os.listdir(fi_d)
                     for fi in dir_files:
-                        fi_path = fi_d + '/' + fi
+                        fi_path = fi_d + '\\' + fi
                         Common.crawler_log().info('dir fi_path = {}'.format(fi_path))
                         # 上传oss
                         if cls.video_file in fi: