ReturnPromoterInfoSpider.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. print(rep.text)
  59. if json.loads(rep.text)["result"] != 1:
  60. errItem = {"result": json.loads(rep.text)["result"]}
  61. return json.dumps(errItem)
  62. else:
  63. data = json.loads(rep.text)["data"]
  64. avgVideoSales = data["promoteBaseInfo"]["avgVideoSales"]
  65. videoSales = data["promoteBaseInfo"]["videoSales"]
  66. sql = "update ruixuan.promoter_info set videoSales= '{videoSales}' , avgVideoSales='{avgVideoSales}' where promoter_id={promoter_id}".format(
  67. videoSales=videoSales,
  68. avgVideoSales=avgVideoSales, promoter_id=promoterId
  69. )
  70. MysqlProUtils().Operate(sql=sql)
  71. except Exception as e:
  72. SendFeiShuMsg.send_robot_msg(
  73. 'PromoterUpdate {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
  74. if __name__ == '__main__':
  75. cookie = cookie_update.get_cookie_handler()[0]
  76. id = 1539195167
  77. ReturnPromoterInfoSpider.PromoterInfoSpiderHandler(2631966819, cookie)