| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- """
- Author renyupeng
- coding=utf-8
- @Time : 2023/2/7 2:34 下午
- @Site :
- @File : ReturnPromoterInfoSpider.py
- @Software: PyCharm
- @contact: renyupeng@c-top.com.cn
- @Tel 1501435553
- """
- import json
- import requests
- from utils.cookie_update import cookie_update
- from utils.mysql_helper import insert
- from utils.mysql_utils import MysqlUtils
- from utils.mysql_utils_pro import MysqlProUtils
- from utils.send_feishu_msg import SendFeiShuMsg
- class ReturnPromoterInfoSpider:
- 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)
- print(rep.text, '----------')
- if json.loads(rep.text)["result"] != 1:
- errItem = {"result": json.loads(rep.text)["result"]}
- return json.dumps(errItem)
- else:
- data = json.loads(rep.text)["data"]
- print(data, '----data------')
- returnItem = {
- "city": data["addressInfo"]["city"],
- "province": data["addressInfo"]["province"],
- "fanNum": data["fanNum"],
- "promoterHeadImgUrl": data["promoterHeadImgUrl"],
- "promoterNickName": data["promoterNickName"],
- "totalSale": data["promoteBaseInfo"]["totalSale"],
- "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
- "videoSales": data["promoteBaseInfo"]["videoSales"]
- }
- returnItemJson = json.dumps(returnItem)
- print(returnItemJson, '----returnItemJson-----')
- return returnItemJson
- except Exception as e:
- SendFeiShuMsg.send_robot_msg(
- 'ReturnPromoterInfoSpider {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
- @staticmethod
- def PromoterUpdate(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)
- print(rep, '--------rep--------')
- if json.loads(rep.text)["result"] != 1:
- errItem = {"result": json.loads(rep.text)["result"]}
- return json.dumps(errItem)
- else:
- data = json.loads(rep.text)["data"]
- avgVideoSales = data["promoteBaseInfo"]["avgVideoSales"]
- videoSales = data["promoteBaseInfo"]["videoSales"]
- sql = "update ruixuan.promoter_info set videoSales= '{videoSales}' , avgVideoSales='{avgVideoSales}' where promoter_id={promoter_id}".format(
- videoSales=videoSales,
- avgVideoSales=avgVideoSales, promoter_id=promoterId
- )
- MysqlProUtils().Operate(sql=sql)
- except Exception as e:
- SendFeiShuMsg.send_robot_msg(
- 'PromoterUpdate {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoterId, e=e))
- if __name__ == '__main__':
- 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'
- id = 643574196
- rolls = ReturnPromoterInfoSpider.PromoterInfoSpiderHandler(id, cookie)
- print(rolls,'---rolls---')
|