wangkun 2 سال پیش
والد
کامیت
4f8e19e3ba
9فایلهای تغییر یافته به همراه157 افزوده شده و 18 حذف شده
  1. BIN
      .DS_Store
  2. 0 3
      chlsfiles/__init__.py
  3. 9 0
      main/common.py
  4. 4 2
      main/demo.py
  5. 125 3
      main/download_publish.py
  6. 2 2
      main/publish.py
  7. 13 6
      main/run_shipinhao_recommend.py
  8. 3 1
      main/shipinhao_get_url.py
  9. 1 1
      main/shipinhao_recommend.py

BIN
.DS_Store


+ 0 - 3
chlsfiles/__init__.py

@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/9/1

+ 9 - 0
main/common.py

@@ -84,6 +84,15 @@ class Common:
                 os.remove(logs_dir + file)
         cls.logger(log_type).info("清除冗余日志成功\n")
 
+    @classmethod
+    def del_charles_files(cls, log_type):
+        # 目标文件夹下所有文件
+        all_file = sorted(os.listdir("./chlsfiles/"))
+        # for file in all_file[0:-1]:
+        for file in all_file:
+            os.remove(r"./chlsfiles/" + file)
+        cls.logger(log_type).info("删除 charles 缓存文件成功\n")
+
     # 封装下载视频或封面的方法
     @classmethod
     def download_method(cls, log_type, text, d_name, d_url):

+ 4 - 2
main/demo.py

@@ -1,5 +1,6 @@
 # @Author: wangkun
 # @Time: 2月 25, 2022
+import datetime
 import logging
 import os
 import time
@@ -89,6 +90,7 @@ def split_title():
 
 if __name__ == "__main__":
     # print(float(str(1.2)))
-    split_title()
-
+    # split_title()
+    print(str(datetime.datetime.now()).split('.')[0])
+    print(time.time())
     pass

+ 125 - 3
main/download_publish.py

@@ -1,16 +1,138 @@
 # -*- coding: utf-8 -*-
 # @Author: wangkun
 # @Time: 2022/9/1
+import random
+import time
+
+from main.common import Common
+from main.feishu_lib import Feishu
+from main.publish import Publish
 
 
 class Download:
     @classmethod
     def download_publish(cls, log_type, env):
-        pass
+        try:
+            recommend_sheet = Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')
+            for i in range(1, len(recommend_sheet)):
+                download_title = recommend_sheet[i][2].strip().replace('"', '') \
+                    .replace('“', '').replace('“', '…').replace("\n", "") \
+                    .replace("/", "").replace("\r", "").replace("#", "") \
+                    .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
+                    .replace(":", "").replace("*", "").replace("?", "") \
+                    .replace("?", "").replace('"', "").replace("<", "") \
+                    .replace(">", "").replace("|", "").replace(" ", "")
+                download_duration = recommend_sheet[i][3]
+                download_like_cnt = recommend_sheet[i][4]
+                download_share_cnt = recommend_sheet[i][5]
+                download_favorite_cnt = recommend_sheet[i][6]
+                download_comment_cnt = recommend_sheet[i][7]
+                download_username = recommend_sheet[i][8]
+                download_head_url = recommend_sheet[i][9]
+                download_cover_url = recommend_sheet[i][10]
+                download_video_url = recommend_sheet[i][11]
+
+                Common.logger(log_type).info("download_title:{}", download_title)
+                Common.logger(log_type).info("download_username:{}", download_username)
+                Common.logger(log_type).info("download_video_url:{}", download_video_url)
+                # Common.logger(log_type).info("download_vid:{}", download_vid)
+                # Common.logger(log_type).info("download_play_cnt:{}", download_play_cnt)
+                # Common.logger(log_type).info("download_like_cnt:{}", download_like_cnt)
+                # Common.logger(log_type).info("download_duration:{}", download_duration)
+                # Common.logger(log_type).info("download_userid:{}", download_userid)
+                # Common.logger(log_type).info("download_head_url:{}", download_head_url)
+                # Common.logger(log_type).info("download_cover_url:{}", download_cover_url)
+
+                # 判断空行
+                if download_video_url is None or download_title is None:
+                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info("空行,删除成功\n")
+                    return
+                # 已下载判断
+                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
+                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info("视频已下载\n")
+                    return
+                # 已存在
+                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x in y]:
+                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info("视频已存在\n")
+                    return
+                else:
+                    # 下载封面
+                    Common.download_method(log_type=log_type, text="cover",
+                                           d_name=str(download_title), d_url=str(download_cover_url))
+                    # 下载视频
+                    Common.download_method(log_type=log_type, text="video",
+                                           d_name=str(download_title), d_url=str(download_video_url))
+
+                    # 保存视频信息至 "./videos/{download_video_title}/info.txt"
+                    with open("./videos/" + download_title
+                              + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
+                        f_a.write('shipinhao' + "\n" +
+                                  str(download_title) + "\n" +
+                                  str(download_duration) + "\n" +
+                                  str(download_favorite_cnt) + "\n" +
+                                  str(download_comment_cnt) + "\n" +
+                                  str(download_like_cnt) + "\n" +
+                                  str(download_share_cnt) + "\n" +
+                                  str(1920*1080) + "\n" +
+                                  str(int(time.time())) + "\n" +
+                                  str(download_username) + "\n" +
+                                  str(download_head_url) + "\n" +
+                                  str(download_video_url) + "\n" +
+                                  str(download_cover_url) + "\n" +
+                                  "shipinhao")
+                    Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
+
+                    # 上传视频
+                    Common.logger(log_type).info("开始上传视频:{}".format(download_title))
+                    our_video_id = Publish.upload_and_publish(log_type, env, "play")
+                    our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
+                    Common.logger(log_type).info("视频上传完成:{}", download_title)
+
+                    # 视频ID工作表,插入首行
+                    Feishu.insert_columns(log_type, "shipinhao", "c77cf9", "ROWS", 1, 2)
+                    # 视频ID工作表,首行写入数据
+                    upload_time = int(time.time())
+                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
+                               "推荐榜",
+                               str(download_title),
+                               our_video_link,
+                               download_duration,
+                               download_like_cnt,
+                               download_share_cnt,
+                               download_favorite_cnt,
+                               download_comment_cnt,
+                               str(download_username),
+                               str(download_head_url),
+                               str(download_cover_url),
+                               str(download_video_url)]]
+                    time.sleep(1)
+                    Feishu.update_values(log_type, "shipinhao", "c77cf9", "F2:Z2", values)
+
+                    # 删除行或列,可选 ROWS、COLUMNS
+                    Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", i + 1, i + 1)
+                    Common.logger(log_type).info("视频:{},下载/上传成功\n", download_title)
+                    return
+        except Exception as e:
+            Common.logger(log_type).error("download_publish异常:{}\n", e)
+            Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", 2, 2)
 
     @classmethod
-    def run_download_publish(cls):
-        pass
+    def run_download_publish(cls, log_type, env):
+        try:
+            while True:
+                time.sleep(1)
+                recommend_sheet = Feishu.get_values_batch(log_type, "shipinhao", "FSDlBy")
+                if len(recommend_sheet) == 1:
+                    Common.logger(log_type).info("下载/上传完成\n")
+                    break
+                else:
+                    cls.download_publish(log_type, env)
+                    time.sleep(random.randint(1, 3))
+        except Exception as e:
+            Common.logger(log_type).error("run_download_publish异常:{}", e)
 
 
 if __name__ == '__main__':

+ 2 - 2
main/publish.py

@@ -141,8 +141,8 @@ class Publish:
     info_file = 'info'
     uids_dev_up = [6267140]
     uids_dev_play = [6267141]
-    uids_prod_up = [20631248, 20631249, 20631250, 20631251, 20631252]
-    uids_prod_play = [20631248, 20631249, 20631250, 20631251, 20631252]
+    uids_prod_up = [20631278, 20631279]
+    uids_prod_play = [20631278, 20631279]
 
     @classmethod
     def upload_and_publish(cls, log_type, env, job):

+ 13 - 6
main/run_shipinhao_recommend.py

@@ -1,10 +1,13 @@
 # -*- coding: utf-8 -*-
 # @Author: wangkun
 # @Time: 2022/8/31
+import datetime
 import os
 import sys
 import time
 
+from main.download_publish import Download
+
 sys.path.append(os.getcwd())
 # from crawler_shipinhao.main.common import Common
 # from crawler_shipinhao.main.shipinhao_recommend import Recommend
@@ -13,13 +16,17 @@ from main.shipinhao_recommend import Recommend
 
 
 class Main:
-    @staticmethod
-    def main():
+    @classmethod
+    def main(cls, env):
         while True:
-            Recommend.start_wechat('recommend')
-            Common.del_logs('recommend')
-            time.sleep(5)
+            if 20 >= datetime.datetime.now().hour >= 10:
+                Recommend.start_wechat('recommend')
+                Download.run_download_publish('recommend', env)
+                Common.del_logs('recommend')
+                time.sleep(5)
+            else:
+                pass
 
 
 if __name__ == '__main__':
-    Main.main()
+    Main.main('dev')

+ 3 - 1
main/shipinhao_get_url.py

@@ -148,4 +148,6 @@ if __name__ == '__main__':
     # GetUrl.write_url('recommend')
     # print(len(Feishu.get_values_batch('recommend', 'shipinhao', 'FSDlBy')))
     while True:
-        GetUrl.run_get_url('recommend')
+        # GetUrl.run_get_url('recommend')
+        Common.del_charles_files('recommend')
+        time.sleep(3)

+ 1 - 1
main/shipinhao_recommend.py

@@ -108,7 +108,7 @@ class Recommend:
                 # 视频标题
                 try:
                     title_id = driver.find_element(By.ID, 'com.tencent.mm:id/ki5')
-                    video_title = title_id.get_attribute('name').split('\n')[0].replace('#', '')
+                    video_title = title_id.get_attribute('name').split('\n')[0].replace('#', '').strip()
                 except NoSuchElementException:
                     video_title = ''
                     driver.swipe(500, 1500, 500, 500, 300)