ReturnPromoterInfoSpider.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.mysql_utils_pro import MysqlProUtils
  17. from utils.send_feishu_msg import SendFeiShuMsg
  18. class ReturnPromoterInfoSpider:
  19. def __init__(self):
  20. self.conn = MysqlUtils()
  21. @staticmethod
  22. def PromoterInfoSpiderHandler(promoterId, cookie):
  23. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  24. promoterId=promoterId)
  25. headers = {'User-Agent': 'Mozilla/5.0',
  26. 'Cookie': cookie}
  27. try:
  28. rep = requests.get(url=url, headers=headers)
  29. if json.loads(rep.text)["result"] != 1:
  30. errItem = {"result": json.loads(rep.text)["result"]}
  31. return json.dumps(errItem)
  32. else:
  33. data = json.loads(rep.text)["data"]
  34. returnItem = {
  35. "city": data["addressInfo"]["city"],
  36. "province": data["addressInfo"]["province"],
  37. "fanNum": data["fanNum"],
  38. "promoterHeadImgUrl": data["promoterHeadImgUrl"],
  39. "promoterNickName": data["promoterNickName"],
  40. "totalSale": data["promoteBaseInfo"]["totalSale"],
  41. "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
  42. "videoSales": data["promoteBaseInfo"]["videoSales"]
  43. }
  44. returnItemJson = json.dumps(returnItem)
  45. return returnItemJson
  46. except Exception as e:
  47. SendFeiShuMsg.send_robot_msg(
  48. 'ReturnPromoterInfoSpider {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
  49. @staticmethod
  50. def PromoterUpdate(promoterId, cookie):
  51. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  52. promoterId=promoterId)
  53. headers = {'User-Agent': 'Mozilla/5.0',
  54. 'Cookie': cookie}
  55. try:
  56. rep = requests.get(url=url, headers=headers)
  57. if json.loads(rep.text)["result"] != 1:
  58. errItem = {"result": json.loads(rep.text)["result"]}
  59. return json.dumps(errItem)
  60. else:
  61. data = json.loads(rep.text)["data"]
  62. avgVideoSales = data["promoteBaseInfo"]["avgVideoSales"]
  63. videoSales = data["promoteBaseInfo"]["videoSales"]
  64. sql = "update ruixuan.promoter_info set videoSales= '{videoSales}' , avgVideoSales='{avgVideoSales}' where promoter_id={promoter_id}".format(
  65. videoSales=videoSales,
  66. avgVideoSales=avgVideoSales, promoter_id=promoterId
  67. )
  68. MysqlProUtils().Operate(sql=sql)
  69. except Exception as e:
  70. SendFeiShuMsg.send_robot_msg(
  71. 'PromoterUpdate {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
  72. if __name__ == '__main__':
  73. cookie = cookie_update.get_cookie_handler()[0]
  74. id = 1539195167
  75. ReturnPromoterInfoSpider.PromoterInfoSpiderHandler(2631966819, cookie)