renyupeng 2 年之前
父節點
當前提交
182776f036
共有 1 個文件被更改,包括 90 次插入47 次删除
  1. 90 47
      spider/PromoterFansInfo.py

+ 90 - 47
spider/PromoterFansInfo.py

@@ -51,54 +51,91 @@ class PromoterFansInfo:
 
 
                     fans_type_date_list = []
                     fans_type_date_list = []
                     fans_base_table = 'kwai_promoter_fans_base_info'
                     fans_base_table = 'kwai_promoter_fans_base_info'
-                    fansProvinceFeatureList = tuple(data["fansProvinceFeature"])
-                    for fansProvinceFeature in fansProvinceFeatureList:
-                        fansProvinceFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'Province',
-                                                   "type_date": fansProvinceFeature["provinceFeature"],
-                                                   "FeatureRate": fansProvinceFeature["provinceFeatureRate"]}
-                        fans_type_date_list.append(fansProvinceFeatureItem)
-                    fansAgeFeatureList = tuple(data["fansAgeFeature"])
-                    for fansAgeFeature in fansAgeFeatureList:
-                        fansAgeFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'Age',
-                                              "type_date": fansAgeFeature["ageFeature"],
-                                              "FeatureRate": fansAgeFeature["ageFeatureRate"]}
-                        fans_type_date_list.append(fansAgeFeatureItem)
-                    fansCityFeatureList = tuple(data["fansCityFeature"])
-                    for fansCityFeature in fansCityFeatureList:
-                        fansCityFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'City',
-                                               "type_date": fansCityFeature["cityFeature"],
-                                               "FeatureRate": fansCityFeature["cityFeatureRate"]}
-                        fans_type_date_list.append(fansCityFeatureItem)
-                    fansCityLevelFeatureList = tuple(data["fansCityLevelFeature"])
-                    for fansCityLevelFeature in fansCityLevelFeatureList:
-                        fansCityLevelFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'CityLevel',
-                                                    "type_date": fansCityLevelFeature["cityLevelFeature"],
-                                                    "FeatureRate": fansCityLevelFeature["cityLevelRate"]}
-                        fans_type_date_list.append(fansCityLevelFeatureItem)
-                    fansEquipBrandFeatureList = tuple(data["fansEquipBrandFeature"])
-                    for fansEquipBrandFeature in fansEquipBrandFeatureList:
-                        fansEquipBrandFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'EquipBrand',
-                                                     "type_date": fansEquipBrandFeature["equipBrandTitleFeature"],
-                                                     "FeatureRate": fansEquipBrandFeature["equipBrandFeatureRate"]}
-                        fans_type_date_list.append(fansEquipBrandFeatureItem)
-                    fansEquipPriceFeatureList = tuple(data["fansEquipPriceFeature"])
-                    for fansEquipPriceFeature in fansEquipPriceFeatureList:
-                        fansEquipPriceFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'EquipPrice',
-                                                     "type_date": fansEquipPriceFeature["equipPriceFeature"],
-                                                     "FeatureRate": fansEquipPriceFeature["equipPriceFeatureRate"]}
-                        fans_type_date_list.append(fansEquipPriceFeatureItem)
-                    promoteAvgPriceList = tuple(data["promoteAvgPrice"])
-                    for promoteAvgPrice in promoteAvgPriceList:
-                        promoteAvgPriceItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'promoteAvgPrice',
-                                               "type_date": promoteAvgPrice["avgPriceFeature"],
-                                               "FeatureRate": promoteAvgPrice["avgPriceFeatureRate"]}
-                        fans_type_date_list.append(promoteAvgPriceItem)
+                    if data["fansProvinceFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 fansProvinceFeature 数据 is None".format(promoterId=promoterId))
+                    else:
+                        fansProvinceFeatureList = tuple(data["fansProvinceFeature"])
+                        for fansProvinceFeature in fansProvinceFeatureList:
+                            fansProvinceFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'Province',
+                                                       "type_date": fansProvinceFeature["provinceFeature"],
+                                                       "FeatureRate": fansProvinceFeature["provinceFeatureRate"]}
+                            fans_type_date_list.append(fansProvinceFeatureItem)
+
+                    if data["fansAgeFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝fansAgeFeature数据 is None".format(promoterId=promoterId))
+                    else:
+                        fansAgeFeatureList = tuple(data["fansAgeFeature"])
+                        for fansAgeFeature in fansAgeFeatureList:
+                            fansAgeFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'Age',
+                                                  "type_date": fansAgeFeature["ageFeature"],
+                                                  "FeatureRate": fansAgeFeature["ageFeatureRate"]}
+                            fans_type_date_list.append(fansAgeFeatureItem)
+                    if data["fansCityFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 fansCityFeature 数据 is None".format(promoterId=promoterId))
+                    else:
+                        fansCityFeatureList = tuple(data["fansCityFeature"])
+                        for fansCityFeature in fansCityFeatureList:
+                            fansCityFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'City',
+                                                   "type_date": fansCityFeature["cityFeature"],
+                                                   "FeatureRate": fansCityFeature["cityFeatureRate"]}
+                            fans_type_date_list.append(fansCityFeatureItem)
+                    if data["fansCityLevelFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 fansCityLevelFeature 数据 is None".format(promoterId=promoterId))
+                    else:
+                        fansCityLevelFeatureList = tuple(data["fansCityLevelFeature"])
+                        for fansCityLevelFeature in fansCityLevelFeatureList:
+                            fansCityLevelFeatureItem = {"promoterId": promoterId, "timeRangeType": i,
+                                                        "type": 'CityLevel',
+                                                        "type_date": fansCityLevelFeature["cityLevelFeature"],
+                                                        "FeatureRate": fansCityLevelFeature["cityLevelRate"]}
+                            fans_type_date_list.append(fansCityLevelFeatureItem)
+                    if data["fansEquipBrandFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 fansEquipBrandFeature 数据 is None".format(promoterId=promoterId))
+                    else:
+                        fansEquipBrandFeatureList = tuple(data["fansEquipBrandFeature"])
+                        for fansEquipBrandFeature in fansEquipBrandFeatureList:
+                            fansEquipBrandFeatureItem = {"promoterId": promoterId, "timeRangeType": i,
+                                                         "type": 'EquipBrand',
+                                                         "type_date": fansEquipBrandFeature["equipBrandTitleFeature"],
+                                                         "FeatureRate": fansEquipBrandFeature["equipBrandFeatureRate"]}
+                            fans_type_date_list.append(fansEquipBrandFeatureItem)
+                    if data["fansEquipPriceFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 fansEquipPriceFeature 数据 is None".format(promoterId=promoterId))
+                    else:
+                        fansEquipPriceFeatureList = tuple(data["fansEquipPriceFeature"])
+                        for fansEquipPriceFeature in fansEquipPriceFeatureList:
+                            fansEquipPriceFeatureItem = {"promoterId": promoterId, "timeRangeType": i,
+                                                         "type": 'EquipPrice',
+                                                         "type_date": fansEquipPriceFeature["equipPriceFeature"],
+                                                         "FeatureRate": fansEquipPriceFeature["equipPriceFeatureRate"]}
+                            fans_type_date_list.append(fansEquipPriceFeatureItem)
+                    if data["promoteAvgPrice"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 promoteAvgPrice 数据 is None".format(promoterId=promoterId))
+                    else:
+                        promoteAvgPriceList = tuple(data["promoteAvgPrice"])
+                        for promoteAvgPrice in promoteAvgPriceList:
+                            promoteAvgPriceItem = {"promoterId": promoterId, "timeRangeType": i,
+                                                   "type": 'promoteAvgPrice',
+                                                   "type_date": promoteAvgPrice["avgPriceFeature"],
+                                                   "FeatureRate": promoteAvgPrice["avgPriceFeatureRate"]}
+                            fans_type_date_list.append(promoteAvgPriceItem)
                     fansGenderFeatureList = tuple(data["fansGenderFeature"])
                     fansGenderFeatureList = tuple(data["fansGenderFeature"])
-                    for fansGenderFeature in fansGenderFeatureList:
-                        fansGenderFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'Gender',
-                                                 "type_date": fansGenderFeature["genderFeature"],
-                                                 "FeatureRate": fansGenderFeature["genderFeatureRate"]}
-                        fans_type_date_list.append(fansGenderFeatureItem)
+                    if data["fansGenderFeature"] is None:
+                        SendFeiShuMsg.send_robot_msg(
+                            "达人{promoterId}粉丝 fansGenderFeature 数据 is None".format(promoterId=promoterId))
+                    else:
+                        for fansGenderFeature in fansGenderFeatureList:
+                            fansGenderFeatureItem = {"promoterId": promoterId, "timeRangeType": i, "type": 'Gender',
+                                                     "type_date": fansGenderFeature["genderFeature"],
+                                                     "FeatureRate": fansGenderFeature["genderFeatureRate"]}
+                            fans_type_date_list.append(fansGenderFeatureItem)
                     batch_insert(table_name=fans_base_table, item_list=fans_type_date_list)
                     batch_insert(table_name=fans_base_table, item_list=fans_type_date_list)
                     fans_trend_list = []
                     fans_trend_list = []
                     if i == 3:
                     if i == 3:
@@ -115,3 +152,9 @@ class PromoterFansInfo:
         except Exception as e:
         except Exception as e:
             SendFeiShuMsg.send_robot_msg(
             SendFeiShuMsg.send_robot_msg(
                 'PromoterFansInfo   {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
                 'PromoterFansInfo   {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
+
+
+if __name__ == '__main__':
+    sql = "select cookie from kwai_promoter.kuaishou_supply_chain_cookie"
+    cookie = MysqlUtils().QueryOne(sql)[0]
+    PromoterFansInfo().PromoterFansInfoHandler(cookie=cookie, promoterId=2928679236)