ReturnPromoterInfoSpider.py 3.4 KB

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