Browse Source

快手优化

zhangyong 1 year ago
parent
commit
e42aac97f6
1 changed files with 44 additions and 19 deletions
  1. 44 19
      kuaishou/kuaishou_author/kuaishou_author_scheduling_new.py

+ 44 - 19
kuaishou/kuaishou_author/kuaishou_author_scheduling_new.py

@@ -8,6 +8,9 @@ from datetime import date, timedelta
 import requests
 import json
 import urllib3
+from pandas import datetime
+
+from common.feishu import Feishu
 
 sys.path.append(os.getcwd())
 from common.common import Common
@@ -80,32 +83,36 @@ class KuaishouauthorScheduling:
     def get_videoList(cls, log_type, crawler, user_dict, rule_dict, env):
         pcursor = ""
         mq = MQ(topic_name="topic_crawler_etl_" + env)
+        count = 0
         while True:
-            flag = user_dict["link"].split("_")[0]
-            if flag == "V1":
-                rule_dict = {
-                    "play_cnt": {"min": 10000, "max": 0},
-                    'period': {"min": 90, "max": 90},
-                    'special': 0.01
-                }
-            elif flag == "V2":
-                rule_dict = {
-                    "play_cnt": {"min": 2000, "max": 0},
-                    'period': {"min": 90, "max": 90},
-                    'special': 0.01
-                }
-            elif flag == "V3":
-                rule_dict = {
-                    "play_cnt": {"min": 100, "max": 0},
-                    'period': {"min": 90, "max": 90},
-                    'special': 0.01
-                }
+            if count > 5:
+                return
             time.sleep(random.randint(10, 50))
             url = "https://www.kuaishou.com/graphql"
             if user_dict['link'][0] == "V":
                 link = user_dict["link"][3:]
+                flag = user_dict["link"].split("_")[0]
+                if flag == "V1":
+                    rule_dict = {
+                        "play_cnt": {"min": 10000, "max": 0},
+                        'period': {"min": 90, "max": 90},
+                        'special': 0.01
+                    }
+                elif flag == "V2":
+                    rule_dict = {
+                        "play_cnt": {"min": 2000, "max": 0},
+                        'period': {"min": 90, "max": 90},
+                        'special': 0.01
+                    }
+                elif flag == "V3":
+                    rule_dict = {
+                        "play_cnt": {"min": 100, "max": 0},
+                        'period': {"min": 90, "max": 90},
+                        'special': 0.01
+                    }
             else:
                 link = user_dict["link"]
+
             payload = json.dumps({
                 "operationName": "visionProfilePhotoList",
                 "variables": {
@@ -156,6 +163,7 @@ class KuaishouauthorScheduling:
                     env=env,
                     message=f"response:{response.json()}\n"
                 )
+                Feishu.bot(log_type, 'kuaishou', f'快手cookie失效,请及时更换~')
                 return
             elif "visionProfilePhotoList" not in response.json()["data"]:
                 Common.logger(log_type, crawler).warning(f"response:{response.json()}\n")
@@ -304,6 +312,7 @@ class KuaishouauthorScheduling:
                             message='已中过滤词\n'
                         )
                     elif cls.repeat_video(log_type, crawler, video_dict["video_id"], env) != 0:
+                        count += 1
                         Common.logger(log_type, crawler).info('视频已下载\n')
                         AliyunLogger.logging(
                             code="2002",
@@ -324,6 +333,22 @@ class KuaishouauthorScheduling:
                         video_dict["publish_time"] = video_dict["publish_time_str"]
                         video_dict["strategy_type"] = log_type
                         mq.send_msg(video_dict)
+                        current_time = datetime.now()
+                        timestamp = current_time.strftime("%Y-%m-%d %H:%M:%S")
+                        values = [[
+                            link,
+                            video_id,
+                            video_title,
+                            publish_time_str,
+                            timestamp,
+                            viewCount,
+                            realLikeCount,
+                            feeds[i].get('photo', {}).get('coverUrl', ""),
+                            feeds[i].get('photo', {}).get('photoUrl', "")
+                        ]]
+                        Feishu.insert_columns('kuaishou', 'kuaishou', "ue0rAF", "ROWS", 1, 2)
+                        time.sleep(0.5)
+                        Feishu.update_values('kuaishou', 'kuaishou', "ue0rAF", "A2:Z2", values)
                         cls.download_cnt += 1
 
                 except Exception as e: