ReturnPromoterInfoSpider.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, '----------')
  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. print(data, '----data------')
  36. returnItem = {
  37. "city": data["addressInfo"]["city"],
  38. "province": data["addressInfo"]["province"],
  39. "fanNum": data["fanNum"],
  40. "promoterHeadImgUrl": data["promoterHeadImgUrl"],
  41. "promoterNickName": data["promoterNickName"],
  42. "totalSale": data["promoteBaseInfo"]["totalSale"],
  43. "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
  44. "videoSales": data["promoteBaseInfo"]["videoSales"]
  45. }
  46. returnItemJson = json.dumps(returnItem)
  47. print(returnItemJson, '----returnItemJson-----')
  48. return returnItemJson
  49. except Exception as e:
  50. SendFeiShuMsg.send_robot_msg(
  51. 'ReturnPromoterInfoSpider {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
  52. @staticmethod
  53. def PromoterUpdate(promoterId, cookie):
  54. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  55. promoterId=promoterId)
  56. headers = {'User-Agent': 'Mozilla/5.0',
  57. 'Cookie': cookie}
  58. try:
  59. rep = requests.get(url=url, headers=headers)
  60. print(rep, '--------rep--------')
  61. if json.loads(rep.text)["result"] != 1:
  62. errItem = {"result": json.loads(rep.text)["result"]}
  63. return json.dumps(errItem)
  64. else:
  65. data = json.loads(rep.text)["data"]
  66. avgVideoSales = data["promoteBaseInfo"]["avgVideoSales"]
  67. videoSales = data["promoteBaseInfo"]["videoSales"]
  68. sql = "update ruixuan.promoter_info set videoSales= '{videoSales}' , avgVideoSales='{avgVideoSales}' where promoter_id={promoter_id}".format(
  69. videoSales=videoSales,
  70. avgVideoSales=avgVideoSales, promoter_id=promoterId
  71. )
  72. MysqlProUtils().Operate(sql=sql)
  73. except Exception as e:
  74. SendFeiShuMsg.send_robot_msg(
  75. 'PromoterUpdate {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
  76. if __name__ == '__main__':
  77. cookie = 'cross-site-cookie=bar; did=web_edb485f1d19c33f7478202d941312a87163c; soft_did=1619580708547; sid=kuaishou.shop.b; pluto-ratio-/=42165_10@-1; userId=562684945; kuaishou.shop.b_st=ChJrdWFpc2hvdS5zaG9wLmIuc3QSoAECL4SqupG3cDvim5lLOpAoXrap2I0Y9PhAZFyJiFNkqaB4VKi37DRahJDw9UztUOGlXpW4wc5RYAZ1RSJfCOzwepTBILFw6V9se3NA2wWw2yVd1RZIkNOfh-_3gRgIJ9EEa-PSRodo_pJrES62qUL-XdGyo1hiiFuA38EYSe9cgNK9FZeK_11TxDOkB4jDudbtBWfHrCmAbMU7raOubnmBGhJpyITJotQHlukZ_tQtSKOqv5QiIG9dXaYV1D8G-AP877ziugAW0KdOgsaEQHIpFySDuosBKAUwAQ; kuaishou.shop.b_ph=16b3dc92a988cb293a1a26da009e883d840c'
  78. id = 643574196
  79. rolls = ReturnPromoterInfoSpider.PromoterInfoSpiderHandler(id, cookie)
  80. print(rolls,'---rolls---')