Pārlūkot izejas kodu

添加在进行随机抽样前检查数据长度功能

zhangliang 1 nedēļu atpakaļ
vecāks
revīzija
c6306b7d8f
1 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 4 2
      workers/select_spider_work.py

+ 4 - 2
workers/select_spider_work.py

@@ -25,11 +25,13 @@ def bot_get_video_id():
         if not data:
         if not data:
             return
             return
         data = [json.dumps(item) for item in data]
         data = [json.dumps(item) for item in data]
+
         # 检查 data 列表的长度
         # 检查 data 列表的长度
-        if len(data) < 26:
+        sample_size = 26
+        if len(data) < sample_size:
             random_sample = data
             random_sample = data
         else:
         else:
-            random_sample = random.sample(data, 26)
+            random_sample = random.sample(data, sample_size)
         RedisHelper().get_client().rpush(redis_task, *random_sample)
         RedisHelper().get_client().rpush(redis_task, *random_sample)
         logger.info(f"[R] 早上好数据写入Redis 成功 共写入 {len(random_sample)} 条")
         logger.info(f"[R] 早上好数据写入Redis 成功 共写入 {len(random_sample)} 条")
         remaining_data = [item for item in data if item not in random_sample]
         remaining_data = [item for item in data if item not in random_sample]