ReturnPromoterInfoSpider.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. Author renyupeng
  3. coding=utf-8
  4. @Time : 2023/2/7 2:34 下午
  5. @Site :
  6. @File : ReturnPromoterInfoSpider.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 ReturnPromoterInfoSpider:
  18. def __init__(self):
  19. self.conn = MysqlUtils()
  20. @staticmethod
  21. def PromoterInfoSpiderHandler(promoterId, cookie):
  22. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  23. promoterId=promoterId)
  24. headers = {'User-Agent': 'Mozilla/5.0',
  25. 'Cookie': cookie}
  26. try:
  27. rep = requests.get(url=url, headers=headers)
  28. if json.loads(rep.text)["result"] != 1:
  29. errItem = {"result": json.loads(rep.text)["result"]}
  30. return json.dumps(errItem)
  31. else:
  32. data = json.loads(rep.text)["data"]
  33. returnItem = {
  34. "city": data["addressInfo"]["city"],
  35. "province": data["addressInfo"]["province"],
  36. "fanNum": data["fanNum"],
  37. "promoterHeadImgUrl": data["promoterHeadImgUrl"],
  38. "promoterNickName": data["promoterNickName"],
  39. "totalSale": data["promoteBaseInfo"]["totalSale"],
  40. }
  41. returnItemJson = json.dumps(returnItem)
  42. return returnItemJson
  43. except Exception as e:
  44. SendFeiShuMsg.send_robot_msg(
  45. 'ReturnPromoterInfoSpider {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))