wangkun 2 anos atrás
pai
commit
57ab745cdc
3 arquivos alterados com 34 adições e 17 exclusões
  1. 3 0
      README.md
  2. 7 4
      main/demo.py
  3. 24 13
      main/shipinhao_recommend.py

+ 3 - 0
README.md

@@ -24,6 +24,9 @@
 
 
 #### 需求
+2022/10/12
+1. 同一账号下的作品最多连续抓取两条视频
+
 2022/10/11
 1. 推荐榜,每日入库条数限制:100
 

+ 7 - 4
main/demo.py

@@ -204,12 +204,15 @@ class Demo:
     @classmethod
     def get_sht(cls):
         sht = Feishu.get_values_batch('recommend', 'shipinhao', 'c77cf9')
-        print(len(sht))
+        name1 = sht[1][14]
+        name2 = sht[2][14]
+
+        if '胡成功很努力' in name1 and '胡成功很努力' in name2:
+            print('yes')
+        else:
+            print('no')
 
 
 if __name__ == "__main__":
-    # print(str(datetime.datetime.now()).split('.')[0])
-    # print(time.time())
-    # Demo.run_download_publish('topic', 'prod')
     Demo.get_sht()
     pass

+ 24 - 13
main/shipinhao_recommend.py

@@ -7,6 +7,7 @@ from appium import webdriver
 from appium.webdriver.webdriver import WebDriver
 from selenium.common.exceptions import NoSuchElementException
 from selenium.webdriver.common.by import By
+
 sys.path.append(os.getcwd())
 from main.common import Common
 from main.publish import Publish
@@ -117,7 +118,7 @@ class Recommend:
                 pause_btn = driver.find_element(By.ID, 'com.tencent.mm:id/eh4')
                 pause_btn.click()
                 start_time = driver.find_element(By.ID, 'com.tencent.mm:id/l59').get_attribute('name')
-                start_time = int(start_time.split(':')[0])*60 + int(start_time.split(':')[-1])
+                start_time = int(start_time.split(':')[0]) * 60 + int(start_time.split(':')[-1])
                 try:
                     end_time = driver.find_element(By.ID, 'com.tencent.mm:id/l7i').get_attribute('name')
                 except NoSuchElementException:
@@ -195,13 +196,21 @@ class Recommend:
                     Common.logger(log_type).info('不满足抓取规则,滑动到下一个视频\n')
                     driver.swipe(10, 1600, 10, 300, 200)
 
+                # 连续下载判断
+                elif user_name in Feishu.get_values_batch('recommend', 'shipinhao', 'c77cf9')[1][14] \
+                        and user_name in Feishu.get_values_batch('recommend', 'shipinhao', 'c77cf9')[2][14]:
+                    Common.logger(log_type).info('该用户已连续下载2条视频,滑动到下一个视频\n')
+                    driver.swipe(10, 1600, 10, 300, 200)
+
                 # 已下载表去重
-                elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
+                elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in
+                                          y]:
                     Common.logger(log_type).info('视频已下载,滑动到下一个视频\n')
                     driver.swipe(10, 1600, 10, 300, 200)
 
                 # feeds 表去重
-                elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x in y]:
+                elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x in
+                                          y]:
                     Common.logger(log_type).info('视频已存在,滑动到下一个视频\n')
                     driver.swipe(10, 1600, 10, 300, 200)
 
@@ -251,12 +260,12 @@ class Recommend:
             recommend_feeds_sheet = Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')
             for i in range(1, len(recommend_feeds_sheet)):
                 download_title = recommend_feeds_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(" ", "")
+                    .replace('“', '').replace('“', '…').replace("\n", "") \
+                    .replace("/", "").replace("\r", "").replace("#", "") \
+                    .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
+                    .replace(":", "").replace("*", "").replace("?", "") \
+                    .replace("?", "").replace('"', "").replace("<", "") \
+                    .replace(">", "").replace("|", "").replace(" ", "")
                 download_duration = recommend_feeds_sheet[i][3]
                 download_like_cnt = recommend_feeds_sheet[i][4]
                 download_share_cnt = recommend_feeds_sheet[i][5]
@@ -272,10 +281,11 @@ class Recommend:
                 Common.logger(log_type).info("download_video_url:{}", download_video_url)
 
                 if download_title is None or download_duration is None or download_video_url is None:
-                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i+1, i+1)
+                    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]:
+                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
@@ -296,7 +306,7 @@ class Recommend:
                                   str(download_comment_cnt) + "\n" +
                                   str(download_like_cnt) + "\n" +
                                   str(download_share_cnt) + "\n" +
-                                  str(1920*1080) + "\n" +
+                                  str(1920 * 1080) + "\n" +
                                   str(int(time.time())) + "\n" +
                                   str(download_username) + "\n" +
                                   str(download_head_url) + "\n" +
@@ -308,7 +318,8 @@ class Recommend:
                     Common.logger(log_type).info("开始上传视频:{}".format(download_title))
                     our_video_id = Publish.upload_and_publish(log_type, env, "play")
                     if env == 'dev':
-                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
+                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(
+                            our_video_id) + "/info"
                     else:
                         our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
                     Common.logger(log_type).info("视频上传完成:{}", our_video_link)