Browse Source

update dir path

wangkun 3 years ago
parent
commit
472aecfdd6
3 changed files with 19 additions and 19 deletions
  1. 9 9
      main/common.py
  2. 8 8
      main/download_kuaishou.py
  3. 2 2
      main/download_weishi.py

+ 9 - 9
main/common.py

@@ -31,7 +31,7 @@ class Common:
         生成 log 日志
         """
         # 日志路径
-        log_dir = "./logs/"
+        log_dir = r"./logs/"
         log_path = os.getcwd() + os.sep + log_dir
         if not os.path.isdir(log_path):
             os.makedirs(log_path)
@@ -53,7 +53,7 @@ class Common:
         清除冗余日志文件
         :return: 保留最近 7 个日志
         """
-        log_dir = "./logs/"
+        log_dir = r"./logs/"
         all_files = sorted(os.listdir(log_dir))
         all_logs = []
         for log in all_files:
@@ -77,7 +77,7 @@ class Common:
         下载保存路径:"./files/{d_title}/"
         """
         # 首先创建一个保存该视频相关信息的文件夹
-        video_dir = "./videos/" + d_name + "/"
+        video_dir = ".\\videos\\" + d_name + "\\"
         if not os.path.exists(video_dir):
             os.mkdir(video_dir)
 
@@ -127,12 +127,12 @@ class Common:
         :param t_name: 文件名
         :return: 文件内容
         """
-        with open("./txt/" + t_name, "r", encoding="UTF-8") as f:
+        with open(r"./txt/" + t_name, "r", encoding="UTF-8") as f:
             return f.readlines()
 
     @classmethod
     def kuaishou_download_count(cls):
-        videoid_path = "./txt/kuaishou_videoid.txt"
+        videoid_path = r"./txt/kuaishou_videoid.txt"
         count = 0
         for count, line in enumerate(open(videoid_path, "rb").readlines()):
             count += 1
@@ -140,7 +140,7 @@ class Common:
 
     @classmethod
     def weishi_download_count(cls):
-        videoid_path = "./txt/weishi_videoid.txt"
+        videoid_path = r"./txt/weishi_videoid.txt"
         count = 0
         for count, line in enumerate(open(videoid_path, "rb").readlines()):
             count += 1
@@ -153,9 +153,9 @@ class Common:
         :return:
         """
         # 创建空文件
-        with open("./txt/" + str(cls.today) + "_kuaishou_videoid.txt", "a") as f:
+        with open(r"./txt/" + str(cls.today) + "_kuaishou_videoid.txt", "a") as f:
             f.write("")
-        videoid_path = "./txt/" + str(cls.today) + "_kuaishou_videoid.txt"
+        videoid_path = r"./txt/" + str(cls.today) + "_kuaishou_videoid.txt"
         count = 0
         for count, line in enumerate(open(videoid_path, "rb").readlines()):
             count += 1
@@ -167,7 +167,7 @@ class Common:
         删除快手渠道昨日下载视频数的 txt 文件
         :return:
         """
-        yesterday_kuaishou_videoid_txt_dir = "./txt/"
+        yesterday_kuaishou_videoid_txt_dir = r"./txt/"
         all_files = sorted(os.listdir(yesterday_kuaishou_videoid_txt_dir))
         for file in all_files:
             name = os.path.splitext(file)[0]

+ 8 - 8
main/download_kuaishou.py

@@ -308,7 +308,7 @@ class KuaiShou:
                             else:
                                 basic_time = int(time.time())
                                 Common.crawler_log().info("添加视频信息至kuaishou_feeds.txt:{}".format(video_title))
-                                with open("./txt/kuaishou_feeds.txt", "a", encoding="UTF-8") as f_a:
+                                with open(r"./txt/kuaishou_feeds.txt", "a", encoding="UTF-8") as f_a:
                                     f_a.write(str(basic_time) + " + " +
                                               str(photo_id) + " + " +
                                               str(video_play_cnt) + " + " +
@@ -339,7 +339,7 @@ class KuaiShou:
                                 else:
                                     basic_time = int(time.time())
                                     Common.crawler_log().info("添加视频信息至kuaishou_feeds.txt:{}".format(video_title))
-                                    with open("./txt/kuaishou_feeds.txt", "a", encoding="UTF-8") as f_a:
+                                    with open(r"./txt/kuaishou_feeds.txt", "a", encoding="UTF-8") as f_a:
                                         f_a.write(str(basic_time) + " + " +
                                                   str(photo_id) + " + " +
                                                   str(video_play_cnt) + " + " +
@@ -398,7 +398,7 @@ class KuaiShou:
                 Common.download_method(text="video", d_name=download_video_title, d_url=download_video_url)
 
                 # 保存视频信息至 kuaishou_videoid.txt
-                with open("./txt/kuaishou_videoid.txt", "a", encoding="UTF-8") as fa:
+                with open(r"./txt/kuaishou_videoid.txt", "a", encoding="UTF-8") as fa:
                     fa.write(download_photo_id + "\n")
 
                 # 添加视频 ID 到 list,用于统计当次下载总数
@@ -409,7 +409,7 @@ class KuaiShou:
                 #     fc.write(download_photo_id + "\n")
 
                 # 保存视频信息至 "./videos/{download_video_title}/info.txt"
-                with open("./videos/" + download_video_title + "/info.txt", "a", encoding="UTF-8") as f_a:
+                with open(r"./videos/" + download_video_title + "/info.txt", "a", encoding="UTF-8") as f_a:
                     f_a.write(str(download_photo_id) + "\n" +
                               str(download_video_title) + "\n" +
                               str(download_video_duration) + "\n" +
@@ -435,9 +435,9 @@ class KuaiShou:
 
                 # 删除该视频在kuaishou_feeds.txt中的信息
                 Common.crawler_log().info("删除该视频在kuaishou_feeds.txt中的信息:{}".format(download_video_title))
-                with open("./txt/kuaishou_feeds.txt", "r", encoding="UTF-8") as f_r:
+                with open(r"./txt/kuaishou_feeds.txt", "r", encoding="UTF-8") as f_r:
                     lines = f_r.readlines()
-                with open("./txt/kuaishou_feeds.txt", "w", encoding="utf-8") as f_w:
+                with open(r"./txt/kuaishou_feeds.txt", "w", encoding="utf-8") as f_w:
                     for line in lines:
                         if download_photo_id in line.split(" + ")[1]:
                             continue
@@ -445,9 +445,9 @@ class KuaiShou:
             else:
                 # 删除该视频在 recommend.txt中的信息
                 Common.crawler_log().info("该视频不满足下载规则,删除在kuaishou_feeds.txt中的信息:{}".format(download_video_title))
-                with open("./txt/kuaishou_feeds.txt", "r", encoding="UTF-8") as f_r:
+                with open(r"./txt/kuaishou_feeds.txt", "r", encoding="UTF-8") as f_r:
                     lines = f_r.readlines()
-                with open("./txt/kuaishou_feeds.txt", "w", encoding="utf-8") as f_w:
+                with open(r"./txt/kuaishou_feeds.txt", "w", encoding="utf-8") as f_w:
                     for line in lines:
                         if download_photo_id in line.split(" + ")[1]:
                             continue

+ 2 - 2
main/download_weishi.py

@@ -293,10 +293,10 @@ class Weishi:
                 # 下载视频
                 Common.download_method(text="video", d_name=download_video_title, d_url=download_video_url)
                 # 保存视频信息至 weishi_videoid.txt
-                with open("./txt/weishi_videoid.txt", "a", encoding="UTF-8") as fa:
+                with open(r"./txt/weishi_videoid.txt", "a", encoding="UTF-8") as fa:
                     fa.write(download_video_id + "\n")
                 # 保存视频信息至 "./videos/{download_video_title}/info.txt"
-                with open("./videos/" + download_video_title + "/info.txt", "a", encoding="UTF-8") as f_a:
+                with open(r"./videos/" + download_video_title + "/info.txt", "a", encoding="UTF-8") as f_a:
                     f_a.write(str(download_video_id) + "\n" +
                               str(download_video_title) + "\n" +
                               str(download_video_duration) + "\n" +