renyupeng 1 year ago
parent
commit
28a9ca41d1
2 changed files with 72 additions and 58 deletions
  1. 66 52
      utils/PromoterInfoWebHook.py
  2. 6 6
      utils/cookie_update.py

+ 66 - 52
utils/PromoterInfoWebHook.py

@@ -8,6 +8,9 @@ coding=utf-8
 @contact: renyupeng@c-top.com.cn
 @contact: renyupeng@c-top.com.cn
 @Tel 1501435553
 @Tel 1501435553
 """
 """
+import random
+
+import redis
 from flask import Flask, request, json
 from flask import Flask, request, json
 
 
 from DouyinSpider.SpiderDouyinHeader import SpiderDouyinHeader
 from DouyinSpider.SpiderDouyinHeader import SpiderDouyinHeader
@@ -34,71 +37,82 @@ def api_root():
 
 
 @app.route('/promoterInfo/getPromoterId', methods=['POST'])
 @app.route('/promoterInfo/getPromoterId', methods=['POST'])
 def webhook_get_promoter():
 def webhook_get_promoter():
+    r = redis.Redis(host='192.168.0.193', password='hcst@2022', port=6379, db=0)
     rep = json.loads(request.data)
     rep = json.loads(request.data)
     promoterId = rep["promoterId"]
     promoterId = rep["promoterId"]
     media_id = rep["mediaId"]
     media_id = rep["mediaId"]
     if media_id == '2' or media_id is None:
     if media_id == '2' or media_id is None:
-        cookie = cookie_update.get_cookie_handler()[0]
-        phone_num = cookie_update.get_cookie_handler()[1]
-        roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
-
-        if json.loads(roll).__contains__("result"):
-            if json.loads(roll)["result"] == 100110000:
-                SendFeiShuMsg.send_cookie_robot_msg(
-                    "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
-                cookie_update.update_cookie_handler(phone_num)
-                retry_cookie = cookie_update.get_cookie_handler()[0]
-                rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
-                p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
-                p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
-                p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
-                             args=(promoterId, retry_cookie))
-                p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
-                             args=(promoterId, retry_cookie))
-                p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
-                             args=(promoterId, retry_cookie))
-                p1.start()
-                p2.start()
-                p3.start()
-                p4.start()
-                p5.start()
-                return rollback
+        if r.zcard('kuaishou_shop_click_token') == 0:
+            cookie_update.get_click_coookie_to_redis()
+
+        else:
+            random_member = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
+            random_item = random.choice(random_member)
+            cookie = random_item[0].decode('utf-8')
+            phone_num = int(random_item[1])
+            roll = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
+
+            if json.loads(roll).__contains__("result"):
+                if json.loads(roll)["result"] == 100110000:
+                    cookie_update.r.zrem('kuaishou_shop_click_token', random_item[0])
+                    SendFeiShuMsg.send_cookie_robot_msg(
+                        "cookie 永久失效 轻更新cookie 唯一电话为{phone_num}".format(phone_num=phone_num))
+                    retry_item = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
+                    retry_cookie = retry_item[0].decode('utf-8')
+                    cookie_update.update_cookie_handler(phone_num)
+                    rollback = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
+                    p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
+                    p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
+                    p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
+                                 args=(promoterId, retry_cookie))
+                    p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
+                                 args=(promoterId, retry_cookie))
+                    p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
+                                 args=(promoterId, retry_cookie))
+                    p1.start()
+                    p2.start()
+                    p3.start()
+                    p4.start()
+                    p5.start()
+                    return rollback
+
+                else:
+                    cookie_update.update_temporary_cookie_handler(phone_num)
+                    cookie_update.r.zrem('kuaishou_shop_click_token', random_item[0])
+
+                    retry_item = cookie_update.r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
+                    retry_cookie = retry_item[0].decode('utf-8')
+                    rolls = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
+                    p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
+                    p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
+                    p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
+                                 args=(promoterId, retry_cookie))
+                    p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
+                                 args=(promoterId, retry_cookie))
+                    p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
+                                 args=(promoterId, retry_cookie))
+                    p1.start()
+                    p2.start()
+                    p3.start()
+                    p4.start()
+                    p5.start()
+                    return rolls
 
 
             else:
             else:
-                SendFeiShuMsg.send_cookie_robot_msg(
-                    "cookie 临时失效 唯一电话为{phone_num},临时失效code{code}".format(phone_num=phone_num,
-                                                                         code=json.loads(roll)["result"]))
-                cookie_update.update_temporary_cookie_handler(phone_num)
-                retry_cookie = cookie_update.get_cookie_handler()[0]
-                rolls = ReturnPromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
-                p1 = Process(target=PromoterInfoSpider().PromoterInfoSpiderHandler, args=(promoterId, retry_cookie))
-                p2 = Process(target=PromoterFansInfo().PromoterFansInfoHandler, args=(promoterId, retry_cookie))
-                p3 = Process(target=PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander,
-                             args=(promoterId, retry_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,
                 p4 = Process(target=PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler,
-                             args=(promoterId, retry_cookie))
+                             args=(promoterId, cookie))
                 p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
                 p5 = Process(target=PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler,
-                             args=(promoterId, retry_cookie))
+                             args=(promoterId, cookie))
                 p1.start()
                 p1.start()
                 p2.start()
                 p2.start()
                 p3.start()
                 p3.start()
                 p4.start()
                 p4.start()
                 p5.start()
                 p5.start()
-                return rolls
-
-        else:
-            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()
-            p2.start()
-            p3.start()
-            p4.start()
-            p5.start()
-            return roll
+                cookie_update.r.zrem('kuaishou_shop_click_token', random_item[0])
+                return roll
     else:
     else:
         rep = json.loads(request.data)
         rep = json.loads(request.data)
         promoterId = rep["promoterId"]
         promoterId = rep["promoterId"]

+ 6 - 6
utils/cookie_update.py

@@ -41,13 +41,13 @@ class cookie_update:
         for result in results:
         for result in results:
             cookie_update.r.zadd('kuaishou_shop_token', {result[0]: result[1]})
             cookie_update.r.zadd('kuaishou_shop_token', {result[0]: result[1]})
 
 
-if __name__ == '__main__':
-    # cookie_update.get_coookie_to_redis()
-
-    random_member = cookie_update.r.zrange('kuaishou_shop_token', 0, -1,withscores=True)
-    random_item = random.choice(random_member)
+    @staticmethod
+    def get_click_coookie_to_redis():
+        sql = "select cookie ,phone_num from kwai_promoter.kuaishou_supply_chain_cookie where status =0"
+        results = MysqlUtils().QueryAll(sql)
+        for result in results:
+            cookie_update.r.zadd('kuaishou_shop_click_token', {result[0]: result[1]})
 
 
-    cookie_update.r.zrem('kuaishou_shop_token',random_item[0])