refactor: 移除评论中指定数量和过滤特定关键词的逻辑

This commit is contained in:
Relakkes
2024-01-17 23:02:05 +08:00
parent e0f9a487e4
commit e940a41033
4 changed files with 11 additions and 57 deletions

View File

@@ -145,31 +145,17 @@ class KuaiShouClient:
result = []
pcursor = ""
count = 0 # 计数器,记录已获取的评论数量
while pcursor != "no_more" and (
config.MAX_COMMENTS_PER_POST == 0 or count < config.MAX_COMMENTS_PER_POST):
while pcursor != "no_more":
comments_res = await self.get_video_comments(photo_id, pcursor)
vision_commen_list = comments_res.get("visionCommentList", {})
pcursor = vision_commen_list.get("pcursor", "")
comments = vision_commen_list.get("rootComments", [])
filtered_comments = [] # 存储经过关键词筛选后的评论
for comment in comments:
content = comment.get("content", "")
if not config.COMMENT_KEYWORDS or any(keyword in content for keyword in config.COMMENT_KEYWORDS):
filtered_comments.append(comment)
count += 1
if config.MAX_COMMENTS_PER_POST != 0 and count >= config.MAX_COMMENTS_PER_POST:
break
if callback: # 如果有回调函数,就执行回调函数
await callback(photo_id, filtered_comments)
await callback(photo_id, comments)
result.extend(filtered_comments)
result.extend(comments)
await asyncio.sleep(crawl_interval)
if not is_fetch_sub_comments:
continue