123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- """
- 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()
- def PromoterInfoSpiderHandler(self, promoterId):
- url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
- promoterId=promoterId)
- sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
- cookie = self.conn.QueryOne(sql)[0]
- 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)
- jsons = json.dumps(promoter_info_item)
- return jsons
- except Exception as e:
- SendFeiShuMsg.send_robot_msg('请求错误请检查cookie'.format(e=e))
|