2 Achegas 5f9c2a044e ... c6306b7d8f

Autor SHA1 Mensaxe Data
  zhangliang c6306b7d8f 添加在进行随机抽样前检查数据长度功能 hai 3 meses
  zhangliang 7540a712f1 添加在进行随机抽样前检查数据长度功能 hai 3 meses
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      workers/select_spider_work.py

+ 7 - 1
workers/select_spider_work.py

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