renyupeng 2 éve
szülő
commit
4eea615439

+ 1 - 7
spider/PromoterFansInfo.py

@@ -22,9 +22,7 @@ class PromoterFansInfo:
         self.conn = MysqlUtils()
         self.conn = MysqlUtils()
         self.list = [1, 2, 3]
         self.list = [1, 2, 3]
 
 
-    def PromoterFansInfoHandler(self, promoterId):
-        sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
-        cookie = self.conn.QueryOne(sql)[0]
+    def PromoterFansInfoHandler(self, promoterId, cookie):
         headers = {'User-Agent': 'Mozilla/5.0',
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
                    'Cookie': cookie}
         try:
         try:
@@ -116,7 +114,3 @@ class PromoterFansInfo:
 
 
         except Exception as e:
         except Exception as e:
             SendFeiShuMsg.send_robot_msg('PromoterFansInfo请求错误请检查cookie{e}'.format(e=e))
             SendFeiShuMsg.send_robot_msg('PromoterFansInfo请求错误请检查cookie{e}'.format(e=e))
-
-
-if __name__ == '__main__':
-    PromoterFansInfo().PromoterFansInfoHandler(1424128656)

+ 2 - 3
spider/PromoterInfoSpider.py

@@ -21,11 +21,10 @@ class PromoterInfoSpider:
     def __init__(self):
     def __init__(self):
         self.conn = MysqlUtils()
         self.conn = MysqlUtils()
 
 
-    def PromoterInfoSpiderHandler(self, promoterId):
+    @staticmethod
+    def PromoterInfoSpiderHandler(promoterId, cookie):
         url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
         url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
             promoterId=promoterId)
             promoterId=promoterId)
-        sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
-        cookie = self.conn.QueryOne(sql)[0]
         headers = {'User-Agent': 'Mozilla/5.0',
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
                    'Cookie': cookie}
 
 

+ 2 - 5
spider/PromoterLiveInfoSpider.py

@@ -12,7 +12,7 @@ coding=utf-8
 import json
 import json
 
 
 import requests
 import requests
-from utils.mysql_helper import  insert, batch_insert
+from utils.mysql_helper import insert, batch_insert
 from utils.mysql_utils import MysqlUtils
 from utils.mysql_utils import MysqlUtils
 from utils.send_feishu_msg import SendFeiShuMsg
 from utils.send_feishu_msg import SendFeiShuMsg
 
 
@@ -22,9 +22,7 @@ class PromoterLiveInfoSpider:
         self.conn = MysqlUtils()
         self.conn = MysqlUtils()
         self.list = [1, 2, 3]
         self.list = [1, 2, 3]
 
 
-    def PromoterLiveInfoSpiderHander(self, promoterId):
-        sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
-        cookie = self.conn.QueryOne(sql)[0]
+    def PromoterLiveInfoSpiderHander(self, promoterId, cookie):
         headers = {'User-Agent': 'Mozilla/5.0',
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
                    'Cookie': cookie}
 
 
@@ -104,4 +102,3 @@ class PromoterLiveInfoSpider:
                     batch_insert(table_name=live_analyse_table_name, item_list=live_analyse_item_list)
                     batch_insert(table_name=live_analyse_table_name, item_list=live_analyse_item_list)
         except Exception as e:
         except Exception as e:
             SendFeiShuMsg.send_robot_msg('PromoterLiveInfoSpider请求错误请检查cookie{e}'.format(e=e))
             SendFeiShuMsg.send_robot_msg('PromoterLiveInfoSpider请求错误请检查cookie{e}'.format(e=e))
-

+ 1 - 4
spider/PromoterVideoAnalysisInfo.py

@@ -22,9 +22,7 @@ class PromoterVideoAnalysisInfo:
         self.conn = MysqlUtils()
         self.conn = MysqlUtils()
         self.list = [1, 2, 3]
         self.list = [1, 2, 3]
 
 
-    def PromoterVideoAnalysisInfoHandler(self, promoterId):
-        sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
-        cookie = self.conn.QueryOne(sql)[0]
+    def PromoterVideoAnalysisInfoHandler(self, promoterId, cookie):
         headers = {'User-Agent': 'Mozilla/5.0',
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
                    'Cookie': cookie}
 
 
@@ -46,4 +44,3 @@ class PromoterVideoAnalysisInfo:
 
 
         except Exception as e:
         except Exception as e:
             SendFeiShuMsg.send_robot_msg('PromoterVideoAnalysisInfo请求错误请检查cookie{e}'.format(e=e))
             SendFeiShuMsg.send_robot_msg('PromoterVideoAnalysisInfo请求错误请检查cookie{e}'.format(e=e))
-

+ 1 - 5
spider/PromoterVideoAnalysisTrend.py

@@ -22,9 +22,7 @@ class PromoterVideoAnalysisTrend:
         self.conn = MysqlUtils()
         self.conn = MysqlUtils()
         self.list = [1, 2, 3]
         self.list = [1, 2, 3]
 
 
-    def PromoterVideoAnalysisTrendHandler(self, promoterId):
-        sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
-        cookie = self.conn.QueryOne(sql)[0]
+    def PromoterVideoAnalysisTrendHandler(self, promoterId, cookie):
         headers = {'User-Agent': 'Mozilla/5.0',
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
                    'Cookie': cookie}
 
 
@@ -68,5 +66,3 @@ class PromoterVideoAnalysisTrend:
 
 
         except Exception as e:
         except Exception as e:
             SendFeiShuMsg.send_robot_msg('PromoterVideoAnalysisTrend请求错误请检查cookie{e}'.format(e=e))
             SendFeiShuMsg.send_robot_msg('PromoterVideoAnalysisTrend请求错误请检查cookie{e}'.format(e=e))
-
-

+ 3 - 4
spider/ReturnPromoterInfoSpider.py

@@ -21,14 +21,13 @@ class ReturnPromoterInfoSpider:
     def __init__(self):
     def __init__(self):
         self.conn = MysqlUtils()
         self.conn = MysqlUtils()
 
 
-    def PromoterInfoSpiderHandler(self, promoterId):
+    @staticmethod
+    def PromoterInfoSpiderHandler(promoterId, cookie):
+
         url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
         url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
             promoterId=promoterId)
             promoterId=promoterId)
-        sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
-        cookie = self.conn.QueryOne(sql)[0]
         headers = {'User-Agent': 'Mozilla/5.0',
         headers = {'User-Agent': 'Mozilla/5.0',
                    'Cookie': cookie}
                    'Cookie': cookie}
-
         try:
         try:
             rep = requests.get(url=url, headers=headers)
             rep = requests.get(url=url, headers=headers)
             data = json.loads(rep.text)["data"]
             data = json.loads(rep.text)["data"]

+ 11 - 15
utils/PromoterInfoWebHook.py

@@ -8,11 +8,7 @@ coding=utf-8
 @contact: renyupeng@c-top.com.cn
 @contact: renyupeng@c-top.com.cn
 @Tel 1501435553
 @Tel 1501435553
 """
 """
-import time
-from concurrent.futures.thread import ThreadPoolExecutor
-
 from flask import Flask, request, json
 from flask import Flask, request, json
-
 from constant.ConfConstant import ConfConstant
 from constant.ConfConstant import ConfConstant
 from spider.PromoterFansInfo import PromoterFansInfo
 from spider.PromoterFansInfo import PromoterFansInfo
 from spider.PromoterInfoSpider import PromoterInfoSpider
 from spider.PromoterInfoSpider import PromoterInfoSpider
@@ -22,6 +18,7 @@ from spider.PromoterVideoAnalysisTrend import PromoterVideoAnalysisTrend
 from multiprocessing import Process
 from multiprocessing import Process
 
 
 from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
 from spider.ReturnPromoterInfoSpider import ReturnPromoterInfoSpider
+from utils.mysql_utils import MysqlUtils
 
 
 app = Flask(__name__)
 app = Flask(__name__)
 
 
@@ -34,22 +31,21 @@ def api_root():
 def webhook_get_promoter():
 def webhook_get_promoter():
     rep = json.loads(request.data)
     rep = json.loads(request.data)
     promoterId = rep["promoterId"]
     promoterId = rep["promoterId"]
-    # 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,))
+    sql = "select cookie from ruixuan.kuaishou_supply_chain_cookie"
+    cookie = MysqlUtils().QueryOne(sql)[0]
+    rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
+    p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, cookie))
+    p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, cookie))
+    p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander, args=(promoterId, cookie))
+    p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler, args=(promoterId, cookie))
+    p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler, args=(promoterId, cookie))
     p1.start()
     p1.start()
     p2.start()
     p2.start()
     p3.start()
     p3.start()
     p4.start()
     p4.start()
     p5.start()
     p5.start()
-    return reuslt
+    return rollback
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    app.run(port=9999, host=ConfConstant.URL, debug=True)
+    app.run(port=9999, debug=True)