renyupeng 2 năm trước cách đây
mục cha
commit
cda2c10ef1
1 tập tin đã thay đổi với 45 bổ sung47 xóa
  1. 45 47
      spider/PromoterVideoAnalysisTrend.py

+ 45 - 47
spider/PromoterVideoAnalysisTrend.py

@@ -27,52 +27,50 @@ class PromoterVideoAnalysisTrend:
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
 
-        try:
-            for i in self.list:
-                url = "https://cps.kwaixiaodian.com/gateway/distribute/platform/seller/promoter/video/analysis/trend?" \
-                      "promoterId={promoterId}&timeRangeType={timeRangeType}" \
-                    .format(timeRangeType=i, promoterId=promoterId)
-                rep = requests.get(url=url, headers=headers)
+        for i in self.list:
+            url = "https://cps.kwaixiaodian.com/gateway/distribute/platform/seller/promoter/video/analysis/trend?" \
+                  "promoterId={promoterId}&timeRangeType={timeRangeType}" \
+                .format(timeRangeType=i, promoterId=promoterId)
+            rep = requests.get(url=url, headers=headers)
+            try:
                 table_name = 'kwai_promoter_video_analyse_info'
-                if 'token过期或错误' in json.loads(rep.text)["msg"]:
-                    data = json.loads(rep.text)["data"]
-                    promoter_video_analyse_item = {"avgCommentCount": data["avgCommentCount"],
-                                                   "avgLikeCount": data["avgLikeCount"],
-                                                   "avgShareCount": data["avgShareCount"],
-                                                   "avgVideoWatchCount": data["avgVideoWatchCount"],
-                                                   "maxCommentCount": data["maxCommentCount"],
-                                                   "maxLikeCount": data["maxLikeCount"],
-                                                   "maxShareCount": data["maxShareCount"],
-                                                   "maxVideoWatchCount": data["maxVideoWatchCount"],
-                                                   "minCommentCount": data["minCommentCount"],
-                                                   "minLikeCount": data["minLikeCount"],
-                                                   "minShareCount": data["minShareCount"],
-                                                   "minVideoWatchCount": data["minVideoWatchCount"],
-                                                   "promoterId": data["promoterId"],
-                                                   "timeRangeType": i,
-                                                   "trend": json.dumps(data["trend"]),
-                                                   }
-                    insert(table_name=table_name, item=promoter_video_analyse_item)
-                    if i == 3:
-                        trend_name = 'kwai_promoter_video_report_analyse_info'
-                        trends_list = tuple(data["trend"])
-                        trend_list = []
-                        if len(trends_list) == 0:
-                            SendFeiShuMsg.send_robot_msg("达人{promoterId}视频数为零".format(promoterId=promoterId))
-                        else:
-                            for num in range(len(trends_list)):
-                                trend = trends_list[num]
-                                analyse_trend = {"date": trend["date"], "promoterId": promoterId,
-                                                 "commentCount": trend["commentCount"], "likeCount": trend["likeCount"],
-                                                 "shareCount": trend["shareCount"],
-                                                 "videoWatchCount": trend["videoWatchCount"]}
-                                trend_list.append(analyse_trend)
-                            batch_insert(table_name=trend_name, item_list=trend_list)
-                else:
-                    SendFeiShuMsg.send_robot_msg(
-                        '{promoterId},{msg}'.format(promoterId=promoterId, msg=json.loads(rep.text)["msg"]))
+                data = json.loads(rep.text)["data"]
+                promoter_video_analyse_item = {"avgCommentCount": data["avgCommentCount"],
+                                               "avgLikeCount": data["avgLikeCount"],
+                                               "avgShareCount": data["avgShareCount"],
+                                               "avgVideoWatchCount": data["avgVideoWatchCount"],
+                                               "maxCommentCount": data["maxCommentCount"],
+                                               "maxLikeCount": data["maxLikeCount"],
+                                               "maxShareCount": data["maxShareCount"],
+                                               "maxVideoWatchCount": data["maxVideoWatchCount"],
+                                               "minCommentCount": data["minCommentCount"],
+                                               "minLikeCount": data["minLikeCount"],
+                                               "minShareCount": data["minShareCount"],
+                                               "minVideoWatchCount": data["minVideoWatchCount"],
+                                               "promoterId": data["promoterId"],
+                                               "timeRangeType": i,
+                                               "trend": json.dumps(data["trend"]),
+                                               }
+                insert(table_name=table_name, item=promoter_video_analyse_item)
+                if i == 3:
+                    trend_name = 'kwai_promoter_video_report_analyse_info'
+                    trends_list = tuple(data["trend"])
+                    trend_list = []
+                    if len(trends_list) == 0:
+                        SendFeiShuMsg.send_robot_msg("达人{promoterId}视频数为零".format(promoterId=promoterId))
+                    else:
+                        for num in range(len(trends_list)):
+                            trend = trends_list[num]
+                            analyse_trend = {"date": trend["date"], "promoterId": promoterId,
+                                             "commentCount": trend["commentCount"], "likeCount": trend["likeCount"],
+                                             "shareCount": trend["shareCount"],
+                                             "videoWatchCount": trend["videoWatchCount"]}
+                            trend_list.append(analyse_trend)
+                        batch_insert(table_name=trend_name, item_list=trend_list)
+            except Exception as e:
+                SendFeiShuMsg.send_robot_msg(
+                    'PromoterVideoAnalysisTrend  {promoterId}请求错误请检查cookie{e}'.
+                        format(promoterId=promoterId, e=json.loads(rep.text)["msg"]))
+
+
 
-        except Exception as e:
-            SendFeiShuMsg.send_robot_msg(
-                'PromoterVideoAnalysisTrend  {promoterId}请求错误请检查cookie{e}'.
-                    format(promoterId=promoterId, e=e))