PromoterInfoSpider.py 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. @staticmethod
  20. def PromoterInfoSpiderHandler(promoterId, cookie):
  21. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  22. promoterId=promoterId)
  23. headers = {'User-Agent': 'Mozilla/5.0',
  24. 'Cookie': cookie}
  25. try:
  26. rep = requests.get(url=url, headers=headers)
  27. table_name = 'kwai_promoter_info'
  28. data = json.loads(rep.text)["data"]
  29. promoter_info_item = {"addressinfo": json.dumps(data["addressInfo"]),
  30. "alreadylookcontact": data["alreadyLookContact"],
  31. "existEffectInvestment": data["existEffectInvestment"], "fanNum": data["fanNum"],
  32. "firstLookContact": data["firstLookContact"],
  33. "hotSaleBrandInfo": json.dumps(data["hotSaleBrandInfo"]),
  34. "hotSaleChannelInfo": json.dumps(data["hotSaleChannelInfo"]),
  35. "inviteChannelInfo": json.dumps(data["inviteChannelInfo"]),
  36. "inviteCommissionRate": data["inviteCommissionRate"],
  37. "isActivePromoter": data["isActivePromoter"],
  38. "isAllowedInvite": data["isAllowedInvite"], "lookNumber": data["lookNumber"],
  39. "phone": data["phone"], "promoteBaseInfo": json.dumps(data["promoteBaseInfo"]),
  40. "promoterHeadImgUrl": data["promoterHeadImgUrl"], "promoterId": data["promoterId"],
  41. "promoterInviteFee": data["promoterInviteFee"],
  42. "promoterNickName": data["promoterNickName"],
  43. "showContact": data["showContact"], "showContactReason": data["showContactReason"],
  44. "updateTime": data["updateTime"], "userSex": data["userSex"],
  45. "weChat": data["weChat"]}
  46. insert(table_name=table_name, item=promoter_info_item)
  47. base_table_name = 'kwai_promoter_base_info'
  48. promoter_base_info_item = {"addressinfo": (json.dumps(data["addressInfo"]),),
  49. "hotSaleBrandInfo": (json.dumps(data["hotSaleBrandInfo"]),),
  50. "hotSaleChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
  51. "inviteChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
  52. "inviteCommissionRate": data["inviteCommissionRate"],
  53. "avgLiveVisitorCount": data["promoteBaseInfo"]["avgLiveVisitorCount"],
  54. "avgLiveVisitorGmv": data["promoteBaseInfo"]["avgLiveVisitorGmv"],
  55. "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
  56. "avgVideoViewers": data["promoteBaseInfo"]["avgVideoViewers"],
  57. "coopStoresNum": data["promoteBaseInfo"]["coopStoresNum"],
  58. "fansNum": data["promoteBaseInfo"]["fansNum"],
  59. "liveExperienceMSGap": data["promoteBaseInfo"]["liveExperienceMSGap"],
  60. "liveStreamCount": data["promoteBaseInfo"]["liveStreamCount"],
  61. "liveStreamGMV": data["promoteBaseInfo"]["liveStreamGMV"],
  62. "liveStreamGPM": data["promoteBaseInfo"]["liveStreamGPM"],
  63. "liveStreamVisitorCount": data["promoteBaseInfo"]["liveStreamVisitorCount"],
  64. "promoteAvgCustomerPrice": data["promoteBaseInfo"]["promoteAvgCustomerPrice"],
  65. "promoteAvgPrice": data["promoteBaseInfo"]["promoteAvgPrice"],
  66. "promoteLiveCount": data["promoteBaseInfo"]["promoteLiveCount"],
  67. "promoteSaleVolume": data["promoteBaseInfo"]["promoteSaleVolume"],
  68. "promoteStartTime": data["promoteBaseInfo"]["promoteStartTime"],
  69. "promotedProductsNum": data["promoteBaseInfo"]["promotedProductsNum"],
  70. "promoterId": data["promoterId"],
  71. "totalSale": data["promoteBaseInfo"]["totalSale"],
  72. "videoGPM": data["promoteBaseInfo"]["videoGPM"],
  73. "videoNum": data["promoteBaseInfo"]["videoNum"],
  74. "videoSales": data["promoteBaseInfo"]["videoSales"],
  75. "videoViews": data["promoteBaseInfo"]["videoViews"],
  76. "promoterInviteFee": data["promoterInviteFee"],
  77. "promoterNickName": data["promoterNickName"],
  78. "showContact": data["showContact"],
  79. "showContactReason": data["showContactReason"],
  80. "updateTime": data["updateTime"],
  81. "userSex": data["userSex"], "weChat": data["userSex"]}
  82. insert(table_name=base_table_name, item=promoter_base_info_item)
  83. except Exception as e:
  84. SendFeiShuMsg.send_robot_msg(
  85. 'PromoterInfoSpider {promoterId}请求错误请检查cookie'.format(promoterId=promoterId, e=e))