From 5fd50ddc8561c16dfbfaf6163ea928529482779f Mon Sep 17 00:00:00 2001 From: Azide Date: Fri, 20 May 2022 01:53:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86mcbbsnews=E4=B8=ADJa?= =?UTF-8?q?va=E7=89=88=E6=9C=AC=E8=B5=84=E8=AE=AF=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nonebot_bison/platform/mcbbsnews.py | 31 +- .../static/mcbbsnews_java_post-0.txt | 65 + .../static/mcbbsnews_java_post-1.txt | 76 + .../static/mcbbsnews_new_post_html.html | 6504 +++++++++++++++++ .../static/mcbbsnews_post_list_html-0.html | 2552 +++++++ .../static/mcbbsnews_post_list_html-1.html | 2601 +++++++ ...list.json => mcbbsnews_raw_post_list.json} | 0 .../mcbbsnews_raw_post_list_update.json | 218 + tests/platforms/test_mcbbsnews.py | 51 +- 9 files changed, 12079 insertions(+), 19 deletions(-) create mode 100644 tests/platforms/static/mcbbsnews_java_post-0.txt create mode 100644 tests/platforms/static/mcbbsnews_java_post-1.txt create mode 100644 tests/platforms/static/mcbbsnews_new_post_html.html create mode 100644 tests/platforms/static/mcbbsnews_post_list_html-0.html create mode 100644 tests/platforms/static/mcbbsnews_post_list_html-1.html rename tests/platforms/static/{mcbbsnew_raw_post_list.json => mcbbsnews_raw_post_list.json} (100%) create mode 100644 tests/platforms/static/mcbbsnews_raw_post_list_update.json diff --git a/src/plugins/nonebot_bison/platform/mcbbsnews.py b/src/plugins/nonebot_bison/platform/mcbbsnews.py index df31cf1..77b9437 100644 --- a/src/plugins/nonebot_bison/platform/mcbbsnews.py +++ b/src/plugins/nonebot_bison/platform/mcbbsnews.py @@ -58,7 +58,7 @@ class McbbsJavaNews(NewMessage): return post_list - def _gen_post_list(self, raw_post_list): + def _gen_post_list(self, raw_post_list) -> list[RawPost]: post_list = [] for raw_post in raw_post_list: post = {} @@ -80,7 +80,8 @@ class McbbsJavaNews(NewMessage): return post["id"] def get_date(self, post: RawPost) -> int: - return post["date"] + # return post["date"] + return None def get_category(self, post: RawPost) -> Category: match post["category"]: @@ -114,7 +115,8 @@ class McbbsJavaNews(NewMessage): for del_tag in soup.find_all(["div", "span"]): del_tag.extract() # 进一步删除无用尾部 - soup.select("blockquote > strong")[0].extract() + # orig_info=soup.select("blockquote > strong") + # orig_info[0].extract() # 展开所有的a,u和strong标签,展开ul,font标签里的font标签 for unwrap_tag in soup.find_all(["a", "strong", "u", "ul", "font"]): match unwrap_tag.name: @@ -136,7 +138,7 @@ class McbbsJavaNews(NewMessage): if isinstance(sub, NavigableString): text += sub if self._check_str_chinese(text): - post_text += "\n{}".format(_format_text(text, 1)) + post_text += "{}\n".format(_format_text(text, 1)) last_is_empty_line = False case "ul": for li_tag in element.find_all("li"): @@ -145,7 +147,7 @@ class McbbsJavaNews(NewMessage): if isinstance(sub, NavigableString): text += sub if self._check_str_chinese(text): - post_text += "\n{}".format(_format_text(text, 1)) + post_text += "{}\n".format(_format_text(text, 1)) last_is_empty_line = False case _: continue @@ -155,7 +157,7 @@ class McbbsJavaNews(NewMessage): post_text += "\n" last_is_empty_line = True else: - post_text += "\n{}".format(_format_text(element, 1)) + post_text += "{}\n".format(_format_text(element, 1)) last_is_empty_line = False else: continue @@ -167,15 +169,18 @@ class McbbsJavaNews(NewMessage): "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/51.0.2704.63 Safari/537.36" } + async with httpx.AsyncClient() as client: html = await client.get(post_url, headers=headers) - match raw_post["category"]: - case "Java版本资讯": - text, pic_urls = self._javanews_parser(html) - case _: - raise CategoryNotSupport( - "McbbsNews订阅暂不支持 `{}".format(raw_post["category"]) - ) + + match raw_post["category"]: + case "Java版本资讯": + text, pic_urls = self._javanews_parser(html.text) + case _: + raise CategoryNotSupport( + "McbbsNews订阅暂不支持 `{}".format(raw_post["category"]) + ) + return Post( self.name, text=text, diff --git a/tests/platforms/static/mcbbsnews_java_post-0.txt b/tests/platforms/static/mcbbsnews_java_post-0.txt new file mode 100644 index 0000000..e76b3e2 --- /dev/null +++ b/tests/platforms/static/mcbbsnews_java_post-0.txt @@ -0,0 +1,65 @@ +稀有的周四快照!除修复了一些错误以及对一些花里胡哨的标签和命令进行了更改以外,我们还引入了“聊天预览”作为对服务器动态样式的聊天消息进行加密的一种方式。针对这个快照,我们在 +中保留了测试选项 +,该选项可以用于测试的 +选项一起设置为 +。如果你对此感兴趣,尤其是如果你在开服务器的话,我们希望您对此提供反馈 +玩的愉快! + +22W19A的修改内容 + +监守者和铁傀儡现在只能在固体方块上生成 + +22W19A的技术性修改 + +服务器现在可以启用聊天预览,这会在聊天框上显示一个受服务器控制的预览 +对locate和place命令的更改 +PointofInteresttagsCHATPREVIEW聊天预览COMMANDS命令PLACETEMPLATEPLACE模板Theplacecommandcannowalsoplacetemplatesatagivenlocation.Syntax:placetemplate