PromoterVideoAnalysisInfo.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.mysql_helper import insert
  14. from utils.mysql_utils import MysqlUtils
  15. from utils.send_feishu_msg import SendFeiShuMsg
  16. class PromoterVideoAnalysisInfo:
  17. def __init__(self):
  18. self.conn = MysqlUtils()
  19. self.list = [1, 2, 3]
  20. def PromoterVideoAnalysisInfoHandler(self, promoterId, cookie):
  21. headers = {'User-Agent': 'Mozilla/5.0',
  22. 'Cookie': cookie}
  23. try:
  24. for i in self.list:
  25. url = "https://cps.kwaixiaodian.com/gateway/distribute/platform/seller" \
  26. "/promoter/video/analysis/key/indicator?promoterId={promoterId}&timeRangeType={timeRangeType}" \
  27. .format(timeRangeType=i, promoterId=promoterId)
  28. rep = requests.get(url=url, headers=headers)
  29. table_name = 'kwai_promoter_video_info'
  30. data = json.loads(rep.text)["data"]
  31. promoter_video_item = {"commentCount": data["commentCount"], "likeCount": data["likeCount"],
  32. "shareCount": data["shareCount"], "totalSale": data["totalSale"],
  33. "videoCount": data["videoCount"],
  34. "videoWatchCount": data["videoWatchCount"],
  35. "timeRangeType": i, "promoterId": data["promoterId"]}
  36. insert(table_name=table_name, item=promoter_video_item)
  37. except Exception as e:
  38. SendFeiShuMsg.send_robot_msg(
  39. 'PromoterVideoAnalysisInfo {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))