PromoterVideoAnalysisTrend.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """
  2. Author renyupeng
  3. coding=utf-8
  4. @Time : 2023/2/9 11:23 上午
  5. @Site :
  6. @File : PromoterVideoAnalysisTrend.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, batch_insert
  14. from utils.mysql_utils import MysqlUtils
  15. from utils.send_feishu_msg import SendFeiShuMsg
  16. class PromoterVideoAnalysisTrend:
  17. def __init__(self):
  18. self.conn = MysqlUtils()
  19. self.list = [1, 2, 3]
  20. def PromoterVideoAnalysisTrendHandler(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/promoter/video/analysis/trend?" \
  26. "promoterId={promoterId}&timeRangeType={timeRangeType}" \
  27. .format(timeRangeType=i, promoterId=promoterId)
  28. rep = requests.get(url=url, headers=headers)
  29. table_name = 'kwai_promoter_video_analyse_info'
  30. data = json.loads(rep.text)["data"]
  31. promoter_video_analyse_item = {"avgCommentCount": data["avgCommentCount"],
  32. "avgLikeCount": data["avgLikeCount"],
  33. "avgShareCount": data["avgShareCount"],
  34. "avgVideoWatchCount": data["avgVideoWatchCount"],
  35. "maxCommentCount": data["maxCommentCount"],
  36. "maxLikeCount": data["maxLikeCount"],
  37. "maxShareCount": data["maxShareCount"],
  38. "maxVideoWatchCount": data["maxVideoWatchCount"],
  39. "minCommentCount": data["minCommentCount"],
  40. "minLikeCount": data["minLikeCount"],
  41. "minShareCount": data["minShareCount"],
  42. "minVideoWatchCount": data["minVideoWatchCount"],
  43. "promoterId": data["promoterId"],
  44. "timeRangeType": i,
  45. "trend": json.dumps(data["trend"]),
  46. }
  47. insert(table_name=table_name, item=promoter_video_analyse_item)
  48. if i == 3:
  49. trend_name = 'kwai_promoter_video_report_analyse_info'
  50. trends_list = tuple(data["trend"])
  51. trend_list = []
  52. for num in range(len(trends_list)):
  53. trend = trends_list[num]
  54. analyse_trend = {"date": trend["date"], "promoterId": promoterId,
  55. "commentCount": trend["commentCount"], "likeCount": trend["likeCount"],
  56. "shareCount": trend["shareCount"], "videoWatchCount": trend["videoWatchCount"]}
  57. trend_list.append(analyse_trend)
  58. batch_insert(table_name=trend_name, item_list=trend_list)
  59. except Exception as e:
  60. SendFeiShuMsg.send_robot_msg('PromoterVideoAnalysisTrend请求错误请检查cookie{e}'.format(e=e))