From 80ecc53cd3cd376842670975886c838c166162f7 Mon Sep 17 00:00:00 2001 From: Relakkes Date: Wed, 3 Jan 2024 23:08:30 +0800 Subject: [PATCH] fix: #107 --- media_platform/bilibili/core.py | 24 ++---------------------- models/bilibili.py | 2 +- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/media_platform/bilibili/core.py b/media_platform/bilibili/core.py index 618f9e7..7c3e571 100644 --- a/media_platform/bilibili/core.py +++ b/media_platform/bilibili/core.py @@ -147,32 +147,12 @@ class BilibiliCrawler(AbstractCrawler): async with semaphore: try: utils.logger.info(f"[BilibiliCrawler.get_comments] begin get video_id: {video_id} comments ...") - # Read keyword and quantity from config - keywords = config.COMMENT_KEYWORDS - max_comments = config.MAX_COMMENTS_PER_POST - - # Download comments - all_comments = await self.bili_client.get_video_all_comments( + await self.bili_client.get_video_all_comments( video_id=video_id, crawl_interval=random.random(), + callback=bilibili.batch_update_bilibili_video_comments ) - # Filter comments by keyword - if keywords: - filtered_comments = [ - comment for comment in all_comments if - any(keyword in comment["content"]["message"] for keyword in keywords) - ] - else: - filtered_comments = all_comments - - # Limit the number of comments - if max_comments > 0: - filtered_comments = filtered_comments[:max_comments] - - # Update bilibili video comments - await bilibili.batch_update_bilibili_video_comments(video_id, filtered_comments) - except DataFetchError as ex: utils.logger.error(f"[BilibiliCrawler.get_comments] get video_id: {video_id} comment error: {ex}") except Exception as e: diff --git a/models/bilibili.py b/models/bilibili.py index 6ca3e71..63aff57 100644 --- a/models/bilibili.py +++ b/models/bilibili.py @@ -123,7 +123,7 @@ async def update_bilibili_video_comment(video_id: str, comment_item: Dict): local_db_item = { "comment_id": comment_id, "create_time": comment_item.get("ctime"), - "video_id": video_id, + "video_id": str(video_id), "content": content.get("message"), "user_id": user_info.get("mid"), "nickname": user_info.get("uname"),