1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- """
- Author renyupeng
- coding=utf-8
- @Time : 2023/2/7 2:34 下午
- @Site :
- @File : PromoterInfoSpider.py
- @Software: PyCharm
- @contact: renyupeng@c-top.com.cn
- @Tel 1501435553
- """
- import json
- import requests
- from utils.mysql_helper import insert
- from utils.mysql_utils import MysqlUtils
- from utils.send_feishu_msg import SendFeiShuMsg
- class PromoterInfoSpider:
- def __init__(self):
- self.conn = MysqlUtils()
- @staticmethod
- def PromoterInfoSpiderHandler(promoterId, cookie):
- url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
- promoterId=promoterId)
- headers = {'User-Agent': 'Mozilla/5.0',
- 'Cookie': cookie}
- try:
- rep = requests.get(url=url, headers=headers)
- table_name = 'kwai_promoter_info'
- data = json.loads(rep.text)["data"]
- promoter_info_item = {"addressinfo": json.dumps(data["addressInfo"]),
- "alreadylookcontact": data["alreadyLookContact"],
- "existEffectInvestment": data["existEffectInvestment"], "fanNum": data["fanNum"],
- "firstLookContact": data["firstLookContact"],
- "hotSaleBrandInfo": json.dumps(data["hotSaleBrandInfo"]),
- "hotSaleChannelInfo": json.dumps(data["hotSaleChannelInfo"]),
- "inviteChannelInfo": json.dumps(data["inviteChannelInfo"]),
- "inviteCommissionRate": data["inviteCommissionRate"],
- "isActivePromoter": data["isActivePromoter"],
- "isAllowedInvite": data["isAllowedInvite"], "lookNumber": data["lookNumber"],
- "phone": data["phone"], "promoteBaseInfo": json.dumps(data["promoteBaseInfo"]),
- "promoterHeadImgUrl": data["promoterHeadImgUrl"], "promoterId": data["promoterId"],
- "promoterInviteFee": data["promoterInviteFee"],
- "promoterNickName": data["promoterNickName"],
- "showContact": data["showContact"], "showContactReason": data["showContactReason"],
- "updateTime": data["updateTime"], "userSex": data["userSex"],
- "weChat": data["weChat"]}
- insert(table_name=table_name, item=promoter_info_item)
- base_table_name = 'kwai_promoter_base_info'
- promoter_base_info_item = {"addressinfo": (json.dumps(data["addressInfo"]),),
- "hotSaleBrandInfo": (json.dumps(data["hotSaleBrandInfo"]),),
- "hotSaleChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
- "inviteChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
- "inviteCommissionRate": data["inviteCommissionRate"],
- "avgLiveVisitorCount": data["promoteBaseInfo"]["avgLiveVisitorCount"],
- "avgLiveVisitorGmv": data["promoteBaseInfo"]["avgLiveVisitorGmv"],
- "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
- "avgVideoViewers": data["promoteBaseInfo"]["avgVideoViewers"],
- "coopStoresNum": data["promoteBaseInfo"]["coopStoresNum"],
- "fansNum": data["promoteBaseInfo"]["fansNum"],
- "liveExperienceMSGap": data["promoteBaseInfo"]["liveExperienceMSGap"],
- "liveStreamCount": data["promoteBaseInfo"]["liveStreamCount"],
- "liveStreamGMV": data["promoteBaseInfo"]["liveStreamGMV"],
- "liveStreamGPM": data["promoteBaseInfo"]["liveStreamGPM"],
- "liveStreamVisitorCount": data["promoteBaseInfo"]["liveStreamVisitorCount"],
- "promoteAvgCustomerPrice": data["promoteBaseInfo"]["promoteAvgCustomerPrice"],
- "promoteAvgPrice": data["promoteBaseInfo"]["promoteAvgPrice"],
- "promoteLiveCount": data["promoteBaseInfo"]["promoteLiveCount"],
- "promoteSaleVolume": data["promoteBaseInfo"]["promoteSaleVolume"],
- "promoteStartTime": data["promoteBaseInfo"]["promoteStartTime"],
- "promotedProductsNum": data["promoteBaseInfo"]["promotedProductsNum"],
- "promoterId": data["promoterId"],
- "totalSale": data["promoteBaseInfo"]["totalSale"],
- "videoGPM": data["promoteBaseInfo"]["videoGPM"],
- "videoNum": data["promoteBaseInfo"]["videoNum"],
- "videoSales": data["promoteBaseInfo"]["videoSales"],
- "videoViews": data["promoteBaseInfo"]["videoViews"],
- "promoterInviteFee": data["promoterInviteFee"],
- "promoterNickName": data["promoterNickName"],
- "showContact": data["showContact"],
- "showContactReason": data["showContactReason"],
- "updateTime": data["updateTime"],
- "userSex": data["userSex"], "weChat": data["userSex"]}
- insert(table_name=base_table_name, item=promoter_base_info_item)
- except Exception as e:
- SendFeiShuMsg.send_robot_msg(
- 'PromoterInfoSpider {promoterId}请求错误请检查cookie'.format(promoterId=promoterId, e=e))
|