PromoterVideoAnalysisInfo.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. Author renyupeng
  3. coding=utf-8
  4. @Time : 2023/2/9 11:04 上午
  5. @Site :
  6. @File : PromoterVideoAnalysisInfo.py
  7. @Software: PyCharm
  8. @contact: renyupeng@c-top.com.cn
  9. @Tel 1501435553
  10. """
  11. import json
  12. import requests
  13. from utils.cookie_update import cookie_update
  14. from utils.mysql_helper import insert
  15. from utils.mysql_utils import MysqlUtils
  16. from utils.send_feishu_msg import SendFeiShuMsg
  17. class PromoterVideoAnalysisInfo:
  18. def __init__(self):
  19. self.conn = MysqlUtils()
  20. self.list = [1, 2, 3]
  21. def PromoterVideoAnalysisInfoHandler(self, promoterId, cookie):
  22. headers = {'User-Agent': 'Mozilla/5.0',
  23. 'Cookie': cookie}
  24. try:
  25. for i in self.list:
  26. url = "https://cps.kwaixiaodian.com/gateway/distribute/platform/seller" \
  27. "/promoter/video/analysis/key/indicator?promoterId={promoterId}&timeRangeType={timeRangeType}" \
  28. .format(timeRangeType=i, promoterId=promoterId)
  29. rep = requests.get(url=url, headers=headers)
  30. print(rep.text,'--------------')
  31. table_name = 'kwai_promoter_video_info'
  32. data = json.loads(rep.text)["data"]
  33. promoter_video_item = {"commentCount": data["commentCount"], "likeCount": data["likeCount"],
  34. "shareCount": data["shareCount"], "totalSale": data["totalSale"],
  35. "videoCount": data["videoCount"],
  36. "videoWatchCount": data["videoWatchCount"],
  37. "timeRangeType": i, "promoterId": data["promoterId"]}
  38. insert(table_name=table_name, item=promoter_video_item)
  39. except Exception as e:
  40. SendFeiShuMsg.send_robot_msg(
  41. 'PromoterVideoAnalysisInfo {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))