| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | 
							- """
 
- Author renyupeng
 
- coding=utf-8
 
- @Time    : 2023/2/9 11:23 上午
 
- @Site    :
 
- @File    : PromoterVideoAnalysisTrend.py
 
- @Software: PyCharm
 
- @contact: renyupeng@c-top.com.cn
 
- @Tel 1501435553
 
- """
 
- import json
 
- import requests
 
- from utils.cookie_update import cookie_update
 
- from utils.mysql_helper import insert, batch_insert
 
- from utils.mysql_utils import MysqlUtils
 
- from utils.send_feishu_msg import SendFeiShuMsg
 
- class PromoterVideoAnalysisTrend:
 
-     def __init__(self):
 
-         self.conn = MysqlUtils()
 
-         self.list = [1, 2, 3]
 
-     def PromoterVideoAnalysisTrendHandler(self, promoterId, cookie):
 
-         headers = {'User-Agent': 'Mozilla/5.0',
 
-                    'Cookie': cookie}
 
-         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'
 
-                 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"]))
 
 
  |