|
@@ -1,3 +1,4 @@
|
|
|
|
+from datetime import datetime, timedelta
|
|
from spiders.basespider import BaseSpider
|
|
from spiders.basespider import BaseSpider
|
|
from typing import Optional, List, Dict
|
|
from typing import Optional, List, Dict
|
|
import aiohttp
|
|
import aiohttp
|
|
@@ -29,6 +30,8 @@ class AuthorSpider(BaseSpider):
|
|
"""核心循环:处理每个用户的视频"""
|
|
"""核心循环:处理每个用户的视频"""
|
|
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.timeout)) as session:
|
|
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.timeout)) as session:
|
|
while self.current_user_index < len(self.user_list_from_db):
|
|
while self.current_user_index < len(self.user_list_from_db):
|
|
|
|
+ if self.is_less_than_3_minutes():
|
|
|
|
+ return
|
|
# 检查数量限制
|
|
# 检查数量限制
|
|
if not await self.is_video_count_sufficient():
|
|
if not await self.is_video_count_sufficient():
|
|
return
|
|
return
|
|
@@ -99,4 +102,12 @@ class AuthorSpider(BaseSpider):
|
|
|
|
|
|
async def fetch_detail(self, item: Dict) -> Dict:
|
|
async def fetch_detail(self, item: Dict) -> Dict:
|
|
"""账号模式:补充视频详情(子类自行实现)"""
|
|
"""账号模式:补充视频详情(子类自行实现)"""
|
|
- return item # 默认返回原数据
|
|
|
|
|
|
+ return item # 默认返回原数据
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def is_less_than_3_minutes(self):
|
|
|
|
+ now = datetime.now()
|
|
|
|
+ tomorrow = now.date() + timedelta(days=1)
|
|
|
|
+ midnight = datetime.combine(tomorrow, datetime.min.time())
|
|
|
|
+ time_left = midnight - now
|
|
|
|
+ return time_left.total_seconds() < 3 * 60
|