PromoterInfoSpider.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """
  2. Author renyupeng
  3. coding=utf-8
  4. @Time : 2023/2/7 2:34 下午
  5. @Site :
  6. @File : PromoterInfoSpider.py
  7. @Software: PyCharm
  8. @contact: renyupeng@c-top.com.cn
  9. @Tel 1501435553
  10. """
  11. import json
  12. import requests
  13. from utils.mysql_helper import insert
  14. from utils.mysql_utils import MysqlUtils
  15. from utils.send_feishu_msg import SendFeiShuMsg
  16. class PromoterInfoSpider:
  17. def __init__(self):
  18. self.conn = MysqlUtils()
  19. def PromoterInfoSpiderHandler(self, promoterId):
  20. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  21. promoterId=promoterId)
  22. sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
  23. cookie = self.conn.QueryOne(sql)[0]
  24. headers = {'User-Agent': 'Mozilla/5.0',
  25. 'Cookie': cookie}
  26. try:
  27. rep = requests.get(url=url, headers=headers)
  28. table_name = 'kwai_promoter_info'
  29. data = json.loads(rep.text)["data"]
  30. promoter_info_item = {"addressinfo": json.dumps(data["addressInfo"]),
  31. "alreadylookcontact": data["alreadyLookContact"],
  32. "existEffectInvestment": data["existEffectInvestment"], "fanNum": data["fanNum"],
  33. "firstLookContact": data["firstLookContact"],
  34. "hotSaleBrandInfo": json.dumps(data["hotSaleBrandInfo"]),
  35. "hotSaleChannelInfo": json.dumps(data["hotSaleChannelInfo"]),
  36. "inviteChannelInfo": json.dumps(data["inviteChannelInfo"]),
  37. "inviteCommissionRate": data["inviteCommissionRate"],
  38. "isActivePromoter": data["isActivePromoter"],
  39. "isAllowedInvite": data["isAllowedInvite"], "lookNumber": data["lookNumber"],
  40. "phone": data["phone"], "promoteBaseInfo": json.dumps(data["promoteBaseInfo"]),
  41. "promoterHeadImgUrl": data["promoterHeadImgUrl"], "promoterId": data["promoterId"],
  42. "promoterInviteFee": data["promoterInviteFee"],
  43. "promoterNickName": data["promoterNickName"],
  44. "showContact": data["showContact"], "showContactReason": data["showContactReason"],
  45. "updateTime": data["updateTime"], "userSex": data["userSex"],
  46. "weChat": data["weChat"]}
  47. insert(table_name=table_name, item=promoter_info_item)
  48. base_table_name = 'kwai_promoter_base_info'
  49. promoter_base_info_item = {"addressinfo": (json.dumps(data["addressInfo"]),),
  50. "hotSaleBrandInfo": (json.dumps(data["hotSaleBrandInfo"]),),
  51. "hotSaleChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
  52. "inviteChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
  53. "inviteCommissionRate": data["inviteCommissionRate"],
  54. "avgLiveVisitorCount": data["promoteBaseInfo"]["avgLiveVisitorCount"],
  55. "avgLiveVisitorGmv": data["promoteBaseInfo"]["avgLiveVisitorGmv"],
  56. "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
  57. "avgVideoViewers": data["promoteBaseInfo"]["avgVideoViewers"],
  58. "coopStoresNum": data["promoteBaseInfo"]["coopStoresNum"],
  59. "fansNum": data["promoteBaseInfo"]["fansNum"],
  60. "liveExperienceMSGap": data["promoteBaseInfo"]["liveExperienceMSGap"],
  61. "liveStreamCount": data["promoteBaseInfo"]["liveStreamCount"],
  62. "liveStreamGMV": data["promoteBaseInfo"]["liveStreamGMV"],
  63. "liveStreamGPM": data["promoteBaseInfo"]["liveStreamGPM"],
  64. "liveStreamVisitorCount": data["promoteBaseInfo"]["liveStreamVisitorCount"],
  65. "promoteAvgCustomerPrice": data["promoteBaseInfo"]["promoteAvgCustomerPrice"],
  66. "promoteAvgPrice": data["promoteBaseInfo"]["promoteAvgPrice"],
  67. "promoteLiveCount": data["promoteBaseInfo"]["promoteLiveCount"],
  68. "promoteSaleVolume": data["promoteBaseInfo"]["promoteSaleVolume"],
  69. "promoteStartTime": data["promoteBaseInfo"]["promoteStartTime"],
  70. "promotedProductsNum": data["promoteBaseInfo"]["promotedProductsNum"],
  71. "promoterId": data["promoterId"],
  72. "totalSale": data["promoteBaseInfo"]["totalSale"],
  73. "videoGPM": data["promoteBaseInfo"]["videoGPM"],
  74. "videoNum": data["promoteBaseInfo"]["videoNum"],
  75. "videoSales": data["promoteBaseInfo"]["videoSales"],
  76. "videoViews": data["promoteBaseInfo"]["videoViews"],
  77. "promoterInviteFee": data["promoterInviteFee"],
  78. "promoterNickName": data["promoterNickName"],
  79. "showContact": data["showContact"],
  80. "showContactReason": data["showContactReason"],
  81. "updateTime": data["updateTime"],
  82. "userSex": data["userSex"], "weChat": data["userSex"]}
  83. insert(table_name=base_table_name, item=promoter_base_info_item)
  84. jsons = json.dumps(promoter_info_item)
  85. return jsons
  86. except Exception as e:
  87. SendFeiShuMsg.send_robot_msg('请求错误请检查cookie'.format(e=e))