123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- """
- 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)
- 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"]
- 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)
- 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)
- 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 = cookie_update.get_cookie_handler()[0]
- id = 1539195167
- ReturnPromoterInfoSpider.PromoterInfoSpiderHandler(2631966819, cookie)
|