Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 处理topic_info字段缺失的问题 #354

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion nonebot_bison/platform/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def get_category(self, post: RawPost) -> Category:
return self._do_get_category(post_type)

def get_tags(self, raw_post: RawPost) -> list[Tag]:
return [*(tp["topic_name"] for tp in raw_post["display"]["topic_info"]["topic_details"])]
# FIXME: 更深的原因可能是返回格式的变动,需要进一步确认
if topic_info := raw_post["display"].get("topic_info", None):
return [*(tp["topic_name"] for tp in topic_info["topic_details"])]

return []

def _text_process(self, dynamic: str, desc: str, title: str) -> str:
similarity = 1.0 if len(dynamic) == 0 or len(desc) == 0 else text_similarity(dynamic, desc)
Expand Down
30 changes: 30 additions & 0 deletions tests/platforms/test_bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ def without_dynamic(app: App):
}


@pytest.mark.asyncio
async def test_get_tag_without_topic_info(bilibili, bing_dy_list):
simple_raw_post = {
"display": {
"topic_info": {
"topic_details": [
{
"topic_name": "可露希尔的秘密档案",
},
{
"topic_name": "罗德岛相簿",
},
],
},
},
}

simple_raw_post_without_topic_info = {
"display": {
"damedane": "dameyo",
},
}

res1 = bilibili.get_tags(simple_raw_post)
assert res1 == ["可露希尔的秘密档案", "罗德岛相簿"]

res2 = bilibili.get_tags(simple_raw_post_without_topic_info)
assert res2 == []


@pytest.mark.asyncio
async def test_video_forward(bilibili, bing_dy_list):
post = await bilibili.parse(bing_dy_list[1])
Expand Down