renyupeng 1 年之前
父节点
当前提交
d6e4c22645
共有 1 个文件被更改,包括 53 次插入50 次删除
  1. 53 50
      spider/SpiderWeekPromoterInfo.py

+ 53 - 50
spider/SpiderWeekPromoterInfo.py

@@ -32,69 +32,72 @@ class SpiderWeekPromoterInfo:
         if self.r.zcard('kuaishou_shop_token') == 0:
             cookie_update.get_coookie_to_redis()
         else:
-            random_member = cookie_update.r.zrange('kuaishou_shop_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)
+            try:
+                random_member = cookie_update.r.zrange('kuaishou_shop_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_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_token', 0, -1, withscores=True)
-                    retry_cookie = retry_item[0].decode('utf-8')
-                    cookie_update.update_cookie_handler(phone_num)
-                    # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
-                    # PromoterFansInfo().PromoterFansInfoHandler(promoterId, retry_cookie)
-                    # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, retry_cookie)
-                    # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, retry_cookie)
-                    # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, retry_cookie)
+                if json.loads(roll).__contains__("result"):
+                    if json.loads(roll)["result"] == 100110000:
+                        cookie_update.r.zrem('kuaishou_shop_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_token', 0, -1, withscores=True)
+                        retry_cookie = retry_item[0].decode('utf-8')
+                        cookie_update.update_cookie_handler(phone_num)
+                        # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
+                        # PromoterFansInfo().PromoterFansInfoHandler(promoterId, retry_cookie)
+                        # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, retry_cookie)
+                        # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, retry_cookie)
+                        # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, retry_cookie)
 
-                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)
-                    cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
+                        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)
+                        cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
 
-                    retry_item = cookie_update.r.zrange('kuaishou_shop_token', 0, -1, withscores=True)
-                    retry_cookie = retry_item[0].decode('utf-8')
-                    # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
-                    # PromoterFansInfo().PromoterFansInfoHandler(promoterId, retry_cookie)
-                    # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, retry_cookie)
-                    # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, retry_cookie)
-                    # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, retry_cookie)
+                        retry_item = cookie_update.r.zrange('kuaishou_shop_token', 0, -1, withscores=True)
+                        retry_cookie = retry_item[0].decode('utf-8')
+                        # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, retry_cookie)
+                        # PromoterFansInfo().PromoterFansInfoHandler(promoterId, retry_cookie)
+                        # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, retry_cookie)
+                        # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, retry_cookie)
+                        # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, retry_cookie)
 
-            else:
-                # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
-                # PromoterFansInfo().PromoterFansInfoHandler(promoterId, cookie)
-                # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, cookie)
-                # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, cookie)
-                # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, cookie)
-                roll = json.loads(roll)
-                fanNum = roll["fanNum"]
-                totalSale = roll["totalSale"]
-                avgVideoSales = roll["avgVideoSales"]
-                videoSales = roll["videoSales"]
-                sql = """ replace into ruixuan.promoter_sales_info(promoter_id, total_sale, fans_number, avg_video_sales, video_sales) values (
-                {promoterId},'{totalSale}',{fanNum},'{avgVideoSales}','{videoSales}'
-                ) """.format(totalSale=totalSale, fanNum=fanNum, avgVideoSales=avgVideoSales, videoSales=videoSales,
-                             promoterId=promoterId)
-                MysqlProUtils().Operate(sql=sql)
-                cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
+                else:
+                    # PromoterInfoSpider().PromoterInfoSpiderHandler(promoterId, cookie)
+                    # PromoterFansInfo().PromoterFansInfoHandler(promoterId, cookie)
+                    # PromoterLiveInfoSpider().PromoterLiveInfoSpiderHander(promoterId, cookie)
+                    # PromoterVideoAnalysisInfo().PromoterVideoAnalysisInfoHandler(promoterId, cookie)
+                    # PromoterVideoAnalysisTrend().PromoterVideoAnalysisTrendHandler(promoterId, cookie)
+                    roll = json.loads(roll)
+                    fanNum = roll["fanNum"]
+                    totalSale = roll["totalSale"]
+                    avgVideoSales = roll["avgVideoSales"]
+                    videoSales = roll["videoSales"]
+                    sql = """ replace into ruixuan.promoter_sales_info(promoter_id, total_sale, fans_number, avg_video_sales, video_sales) values (
+                    {promoterId},'{totalSale}',{fanNum},'{avgVideoSales}','{videoSales}'
+                    ) """.format(totalSale=totalSale, fanNum=fanNum, avgVideoSales=avgVideoSales, videoSales=videoSales,
+                                 promoterId=promoterId)
+                    MysqlProUtils().Operate(sql=sql)
+                    cookie_update.r.zrem('kuaishou_shop_token', random_item[0])
+            except Exception as e:
+                return
 
     def get_promoter_info(self):
         sql = """
-        select promoter_id from ruixuan.promoter_info 
+        select promoter_id from ruixuan.promoter_info  where promoter_id!=0
         """
         promoter_result = self.conn.QueryAll(sql)
         for promoter in promoter_result:
             promoter_id = int(promoter[0].decode('utf-8'))
             self.get_promoter(promoter_id)
-            time.sleep(2)
+            time.sleep(1)
 
 
 if __name__ == '__main__':