renyupeng 2 年之前
父節點
當前提交
bf8d3dc075
共有 3 個文件被更改,包括 64 次插入12 次删除
  1. 0 4
      spider/PromoterInfoSpider.py
  2. 46 0
      spider/ReturnPromoterInfoSpider.py
  3. 18 8
      utils/PromoterInfoWebHook.py

+ 0 - 4
spider/PromoterInfoSpider.py

@@ -88,9 +88,5 @@ class PromoterInfoSpider:
                                        "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))
-
-

+ 46 - 0
spider/ReturnPromoterInfoSpider.py

@@ -0,0 +1,46 @@
+"""
+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.mysql_helper import insert
+from utils.mysql_utils import MysqlUtils
+from utils.send_feishu_msg import SendFeiShuMsg
+
+
+class ReturnPromoterInfoSpider:
+    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)
+            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"],
+            }
+            returnItemJson = json.dumps(returnItem)
+            return returnItemJson
+        except Exception as e:
+            SendFeiShuMsg.send_robot_msg('请求错误请检查cookie'.format(e=e))

+ 18 - 8
utils/PromoterInfoWebHook.py

@@ -19,6 +19,9 @@ from spider.PromoterInfoSpider import PromoterInfoSpider
 from spider.PromoterLiveInfoSpider import PromoterLiveInfoSpider
 from spider.PromoterVideoAnalysisInfo import PromoterVideoAnalysisInfo
 from spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrend
+from multiprocessing import Process
+
+from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
 
 app = Flask(__name__)
 
@@ -31,14 +34,21 @@ def api_root():
 def webhook_get_promoter():
     rep = json.loads(request.data)
     promoterId = rep["promoterId"]
-    pool = ThreadPoolExecutor(max_workers=10)
-    result = PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId=promoterId)
-    pool.submit(PromoterFansInfo().PromoterFansInfoHandler(promoterId=promoterId))
-    pool.submit(PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId=promoterId))
-    pool.submit(PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId=promoterId))
-    pool.submit(PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId=promoterId))
-    pool.shutdown()
-    return result
+    # pool = multiprocessing.Pool(4)
+    # m = multiprocessing.Manager()
+    print(time.time(), 'p0----')
+    reuslt = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId)
+    p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId,))
+    p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId,))
+    p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId,))
+    p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler, args=(promoterId,))
+    p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler, args=(promoterId,))
+    p1.start()
+    p2.start()
+    p3.start()
+    p4.start()
+    p5.start()
+    return reuslt
 
 
 if __name__ == '__main__':