zhangyong 4 месяцев назад
Родитель
Сommit
5970ee1331
1 измененных файлов с 43 добавлено и 59 удалено
  1. 43 59
      qpl_channel/qpl_cljx.py

+ 43 - 59
qpl_channel/qpl_cljx.py

@@ -5,32 +5,33 @@ from datetime import datetime
 import requests
 import json
 
-from common import Feishu
+from common import Feishu, Material
 from common.sql_help import sqlCollect
 
 
 class QplKs:
     @classmethod
     def ks_star_info(cls):
-        content_type = [{'美食': '673'}, {'旅游': '679'}, {'音乐': '687'}, {'时政资讯': '692'},  {'健康医疗': '684'},
-                        {'军事': '701'}, {'教育培训': '685'}, {'生活': '677'}, {'舞蹈': '688'},
+        content_type = [{'美食': '673'}, {'旅游': '679'}, {'音乐': '687'}, {'教育培训': '685'}, {'时政资讯': '692'},
+                        {'军事': '701'},{'舞蹈': '688'}, {'生活': '677'},
                         {'母婴亲子': '676'}, {'萌宠': '691'}, {'情感': '696'}, {'搞笑': '695'}, {'人文': '697'},
                         {'三农': '694'}, {'科学与法律': '693'}, {'读书': '689'}, {'奇人异象': '700'}, {'民生资讯': '703'},
                         {'纪实类': '705'}, {'财经投资': '690'}, {'摄影': '704'}, {'艺术文化': '682'}, {'房产家居': '683'},
-                        {'短剧': '674'}, {'时尚': '675'}, {'影视娱乐': '702'}, {'体育运动': '680'}, {'健身达人': '706'},
-                        {'星座命理': '699'},  {'汽车': '678'}, {'高新数码': '686'}]
+                        {'时尚': '675'}, {'体育运动': '680'}, {'健身达人': '706'},{'健康医疗': '684'},]
+        #{'星座命理': '699'},  {'汽车': '678'},  {'影视娱乐': '702'},{'短剧': '674'},{'高新数码': '686'}
         fans_count = [{10000000: 0}, {5000000: 10000000}, {3000000: 5000000}, {1000000: 3000000}, {100000: 1000000},  {0: 100000}]
         # fans_count = [{1000000: 3000000}, {100000: 1000000},  {0: 100000}]
 
 
 
         # fans_count = [{10000000: 0}, {5000000: 10000000}]
+        cookie = Material.get_cookie_data("B3LFsemLuhyJPktxIoMcJM6znSh", "c95862", "磁力聚星")
         url = "https://k.kuaishou.com/rest/web/star/list"
         headers = {
             'Accept': 'application/json',
             'Accept-Language': 'zh-CN,zh;q=0.9',
             'Content-Type': 'application/json',
-            'Cookie':'did=web_9c6a04a4004fdb7c95a658a56ed275b6; apdid=328ac94f-4040-41fe-a038-b60140291aca99fb22e9862c74736f53d57b666ee53b:1719580529:1; language=zh-CN; ud=2205012540; app_id=ks686235996059836592; expire_time=1800; didv=1723085291918; bUserId=1000056684959; userId=2574854626; kuaishou.ad.social_st=ChVrdWFpc2hvdS5hZC5zb2NpYWwuc3QSoAEJJtGxri6OS3-aikAamh2BjJmu-JZs4Hms4Q_qmQ3CaFXi9G7Fyws7Ju36XYcFkPxLQA4J0muM7GRCHD62ELpdlm9jCFJZ1Mxlhc1_INbYMGDUw1_eLDdR28sU63cq_IFmKr1Y-FeCslfCScQsEpf7ONMstWAs9rVK5xXR9rJo4mMUzs3SO-yCn46cCO1KTmwlZ3HP1Bka0OOUkygcmaYsGhJFvwGA3YVI_YFUgG1CsjzvX68iIBJsEXmDPZmV6ecc3BJglaBUGmCJm4OfffPWsoEo_eXKKAUwAQ; kuaishou.ad.social_ph=a6dd5c2ef615931d1f9bb18b435cbba68b4f; access_token=ChFvYXV0aC5hY2Nlc3NUb2tlbhIwy3iep1DRAI9G0dB0GGJb5gmv8mG1t6fhB3kFZAu2XYukATXskPWbwtTyHmFFRiWVGhJwAv7lQ4RI-YbDWturzqUxgFYiIFeuj_O9PiCUWE2ZxEHjQtsIhcMf8MWquScrO1zFfi5VKAUwAQ; nc_user_id=CiVhZC5ub3RpZnkuY2VudGVyLm9hdXRoLnVzZXIuaWQuc2VjcmV0EiCQoYYRNwxzlx0MegpAr7yQSMSMtx42XvQYDDBHQT8TExoSLvD4Bd30rDvWnd7Q5GZt/4xpIiAXU84pxZPaf5W2Jwa9F8gALe8XoiphKjU3C8UrGvupLSgFMAE=',
+            'Cookie': cookie,
             'Origin': 'https://k.kuaishou.com',
             'Pragma': 'no-cache',
             'Referer': 'https://k.kuaishou.com/',
@@ -45,7 +46,7 @@ class QplKs:
                     payload_data = {
                         "currentPage": current_page,
                         "pageSize": 20,
-                        "starOrderTag": 3,
+                        "starOrderTag":22,
                         "taskType": 1,
                         "marketingGoal": 1,
                         "viewerAgeList": [  # 观众画像 50+
@@ -65,11 +66,11 @@ class QplKs:
                                 "selectFirstLevelId": True
                             }
                         ],
-                        # "starTagIds": [  # 高调性
-                        #     13
-                        # ]
-                        # "fansMinNum": 1000000,  # 粉丝数量
-                        # "fansMaxNum": 3000000,  # 粉丝数量
+                        "starTagIds": [  # 高调性
+                            13
+                        ],
+                        "fansMinNum": fans_min_num,  # 粉丝数量
+                        "fansMaxNum": fans_max_num,  # 粉丝数量
                     }
                     if fans_min_num > 0:
                         payload_data["fansMinNum"] = fans_min_num
@@ -77,14 +78,23 @@ class QplKs:
                         payload_data["fansMaxNum"] = fans_max_num
                     payload = json.dumps(payload_data)
 
-                    time.sleep(random.randint(5, 10))
+                    time.sleep(random.randint(1, 5))
                     response = requests.request("POST", url, headers=headers, data=payload)
+                    if ": 109" in response.text:
+                        text = (
+                            f"**通知类型**: 磁力聚星cookie过期\n"
+                            f"**链接**: https://w42nne6hzg.feishu.cn/sheets/B3LFsemLuhyJPktxIoMcJM6znSh?sheet=c95862\n"
+                        )
+                        Feishu.finish_bot(text,
+                                          "https://open.feishu.cn/open-apis/bot/v2/hook/ba69e1b6-5839-4640-8932-94f53de5a067",
+                                          "【 磁力聚星cookie过期 】")
+                        time.sleep(360)
+                        response = requests.request("POST", url, headers=headers, data=payload)
                     response = response.json()
                     print(f"开始扫描{content}")
-
-                    result = response["result"]
-                    if result == 1:
-                        try:
+                    try:
+                        result = response["result"]
+                        if result == 1:
                             total = response["total"]  # 总条数
                             if total == 0:
                                 print(f"没有扫描到数据{content}")
@@ -114,42 +124,10 @@ class QplKs:
                                 fans_increase_rate = star["fansIncreaseRate"]  # 粉丝增长率
                                 sqlCollect.insert_ks_star_data(user_id, star_id, name, kwai_id, gender, fans_number, profile_id, star_tag_str, industry_tag_str, photo_expect_play, photo_expect_cpm, photo_interaction_rate, photo_complete_play_rate, fans_increase_num, fans_increase_rate)
                                 print(f"{star_id}-{profile_id}获取列表入库成功")
-                                cls.ks_star_works_info(star_id, profile_id)
-                                time.sleep(random.randint(10, 20))
-                                cls.ks_list_portrait_info(star_id, profile_id)
-                                time.sleep(random.randint(10, 20))
-                                # # if res == 1:
-                                # current_time = datetime.now()
-                                # formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
-                                # if fans_min_num == 0:
-                                #     fans = f"{fans_max_num}及以下"
-                                # if fans_max_num == 0:
-                                #     fans = f"{fans_min_num}及以上"
-                                # else:
-                                #     fans = f"{fans_min_num}~{fans_max_num}"
-                                # values = [
-                                #     [
-                                #         name,
-                                #         gender,
-                                #         fans_number,
-                                #         profile_id,
-                                #         "https://www.kuaishou.com/profile/"+profile_id,
-                                #         star_tag_str,
-                                #         industry_tag_str,
-                                #         photo_expect_play,
-                                #         photo_expect_cpm,
-                                #         photo_interaction_rate,
-                                #         photo_complete_play_rate,
-                                #         fans_increase_num,
-                                #         fans_increase_rate,
-                                #         fans,
-                                #         formatted_time
-                                #     ]
-                                # ]
-                                # Feishu.insert_columns("GjGZsmW2ahaCe4tmzDTc58tVnbe", "COyUUm", "ROWS", 1, 2)
-                                # time.sleep(0.5)
-                                # Feishu.update_values("GjGZsmW2ahaCe4tmzDTc58tVnbe", "COyUUm", "A2:Z2", values)
-                                # print(f"入库到一条数据{content}")
+                                cls.ks_star_works_info(star_id, profile_id, cookie)
+                                time.sleep(random.randint(1, 5))
+                                cls.ks_list_portrait_info(star_id, profile_id, cookie)
+                                time.sleep(random.randint(1, 5))
                             current_page += 1
                             if total < 20:
                                 break
@@ -160,14 +138,15 @@ class QplKs:
                             id = sqlCollect.select_ks_star_data(profile_id)
                             if id:
                                 break
-                        except Exception as e:
-                            print(f"{e}")
+                    except Exception as e:
+                        print(f"{e}")
+                        return
 
     """
     传播表现
     """
     @classmethod
-    def ks_star_works_info(cls, star_id: str, profile_id: str):
+    def ks_star_works_info(cls, star_id: str, profile_id: str, cookie: str):
         url = "https://k.kuaishou.com/rest/web/star/starWorksInfo"
 
         payload = json.dumps({
@@ -179,7 +158,7 @@ class QplKs:
             'Accept-Language': 'zh-CN,zh;q=0.9',
             'Connection': 'keep-alive',
             'Content-Type': 'application/json',
-            'Cookie':'did=web_9c6a04a4004fdb7c95a658a56ed275b6; apdid=328ac94f-4040-41fe-a038-b60140291aca99fb22e9862c74736f53d57b666ee53b:1719580529:1; language=zh-CN; ud=2205012540; app_id=ks686235996059836592; expire_time=1800; didv=1723085291918; bUserId=1000056684959; userId=2574854626; kuaishou.ad.social_st=ChVrdWFpc2hvdS5hZC5zb2NpYWwuc3QSoAEJJtGxri6OS3-aikAamh2BjJmu-JZs4Hms4Q_qmQ3CaFXi9G7Fyws7Ju36XYcFkPxLQA4J0muM7GRCHD62ELpdlm9jCFJZ1Mxlhc1_INbYMGDUw1_eLDdR28sU63cq_IFmKr1Y-FeCslfCScQsEpf7ONMstWAs9rVK5xXR9rJo4mMUzs3SO-yCn46cCO1KTmwlZ3HP1Bka0OOUkygcmaYsGhJFvwGA3YVI_YFUgG1CsjzvX68iIBJsEXmDPZmV6ecc3BJglaBUGmCJm4OfffPWsoEo_eXKKAUwAQ; kuaishou.ad.social_ph=a6dd5c2ef615931d1f9bb18b435cbba68b4f; access_token=ChFvYXV0aC5hY2Nlc3NUb2tlbhIwy3iep1DRAI9G0dB0GGJb5gmv8mG1t6fhB3kFZAu2XYukATXskPWbwtTyHmFFRiWVGhJwAv7lQ4RI-YbDWturzqUxgFYiIFeuj_O9PiCUWE2ZxEHjQtsIhcMf8MWquScrO1zFfi5VKAUwAQ; nc_user_id=CiVhZC5ub3RpZnkuY2VudGVyLm9hdXRoLnVzZXIuaWQuc2VjcmV0EiCQoYYRNwxzlx0MegpAr7yQSMSMtx42XvQYDDBHQT8TExoSLvD4Bd30rDvWnd7Q5GZt/4xpIiAXU84pxZPaf5W2Jwa9F8gALe8XoiphKjU3C8UrGvupLSgFMAE=',
+            'Cookie': cookie,
             'Origin': 'https://k.kuaishou.com',
             'Referer': 'https://k.kuaishou.com/'
         }
@@ -212,14 +191,16 @@ class QplKs:
                 print(f"{star_id}-{profile_id}获取传播表现入库成功")
             except Exception as e:
                 print(f"{star_id}-{profile_id}:{e}")
+                return
         else:
             print(f"{star_id}-{profile_id}获取传播表现失败")
+            return
 
     """
     受众分析
     """
     @classmethod
-    def ks_list_portrait_info(cls, star_id: str, profile_id: str):
+    def ks_list_portrait_info(cls, star_id: str, profile_id: str, cookie: str):
         url = "https://k.kuaishou.com/rest/web/star/listPortrait"
 
         payload = json.dumps({
@@ -231,7 +212,7 @@ class QplKs:
             'Accept-Language': 'zh-CN,zh;q=0.9',
             'Connection': 'keep-alive',
             'Content-Type': 'application/json',
-            'Cookie':'did=web_9c6a04a4004fdb7c95a658a56ed275b6; apdid=328ac94f-4040-41fe-a038-b60140291aca99fb22e9862c74736f53d57b666ee53b:1719580529:1; language=zh-CN; ud=2205012540; app_id=ks686235996059836592; expire_time=1800; didv=1723085291918; bUserId=1000056684959; userId=2574854626; kuaishou.ad.social_st=ChVrdWFpc2hvdS5hZC5zb2NpYWwuc3QSoAEJJtGxri6OS3-aikAamh2BjJmu-JZs4Hms4Q_qmQ3CaFXi9G7Fyws7Ju36XYcFkPxLQA4J0muM7GRCHD62ELpdlm9jCFJZ1Mxlhc1_INbYMGDUw1_eLDdR28sU63cq_IFmKr1Y-FeCslfCScQsEpf7ONMstWAs9rVK5xXR9rJo4mMUzs3SO-yCn46cCO1KTmwlZ3HP1Bka0OOUkygcmaYsGhJFvwGA3YVI_YFUgG1CsjzvX68iIBJsEXmDPZmV6ecc3BJglaBUGmCJm4OfffPWsoEo_eXKKAUwAQ; kuaishou.ad.social_ph=a6dd5c2ef615931d1f9bb18b435cbba68b4f; access_token=ChFvYXV0aC5hY2Nlc3NUb2tlbhIwy3iep1DRAI9G0dB0GGJb5gmv8mG1t6fhB3kFZAu2XYukATXskPWbwtTyHmFFRiWVGhJwAv7lQ4RI-YbDWturzqUxgFYiIFeuj_O9PiCUWE2ZxEHjQtsIhcMf8MWquScrO1zFfi5VKAUwAQ; nc_user_id=CiVhZC5ub3RpZnkuY2VudGVyLm9hdXRoLnVzZXIuaWQuc2VjcmV0EiCQoYYRNwxzlx0MegpAr7yQSMSMtx42XvQYDDBHQT8TExoSLvD4Bd30rDvWnd7Q5GZt/4xpIiAXU84pxZPaf5W2Jwa9F8gALe8XoiphKjU3C8UrGvupLSgFMAE=',
+            'Cookie': cookie,
             'Origin': 'https://k.kuaishou.com',
             'Referer': 'https://k.kuaishou.com/'
         }
@@ -271,6 +252,7 @@ class QplKs:
                     sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, brand_type, brand_name, brand_proportion)
             except Exception as e:
                 print(f"{star_id}-{profile_id}:{e}")
+                return
             mobile_price_percentage = viewer_portrait['mobilePricePercentage']  # 设备价格占比
             for price in mobile_price_percentage:
                 price_type = 'mobile_price_percentage'
@@ -279,8 +261,10 @@ class QplKs:
                 price_proportion = f"{float(value):.3f}%" if value else "0.000%"
                 sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, price_type, price_name, price_proportion)
             print(f"{star_id}-{profile_id}获取受众分析入库成功")
+            return
         else:
             print(f"{star_id}-{profile_id}获取受众分析失败")
+            return