From 45fed0b232af7cb292fb3ad0913eaf0030f33dda Mon Sep 17 00:00:00 2001 From: hemengyang Date: Fri, 18 Feb 2022 18:09:07 +0800 Subject: [PATCH 1/5] feat: add ff14 news --- src/plugins/nonebot_bison/platform/ff14.py | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/plugins/nonebot_bison/platform/ff14.py diff --git a/src/plugins/nonebot_bison/platform/ff14.py b/src/plugins/nonebot_bison/platform/ff14.py new file mode 100644 index 0000000..68be182 --- /dev/null +++ b/src/plugins/nonebot_bison/platform/ff14.py @@ -0,0 +1,45 @@ +from typing import Any + +import httpx + +from ..post import Post +from ..types import RawPost, Target +from .platform import NewMessage + + +class FF14(NewMessage): + + categories = {} + platform_name = "ff14" + name = "最终幻想XIV官方公告" + enable_tag = False + enabled = True + is_common = False + schedule_type = "interval" + schedule_kw = {"seconds": 60} + has_target = False + + async def get_target_name(self, _: Target) -> str: + return "最终幻想XIV官方公告" + + async def get_sub_list(self, _) -> list[RawPost]: + async with httpx.AsyncClient() as client: + raw_data = await client.get( + "https://ff.web.sdo.com/inc/newdata.ashx?url=List?gameCode=ff&category=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5" + ) + return raw_data.json()["Data"] + + def get_id(self, post: RawPost) -> Any: + """用发布时间当作 ID + + 因为有时候官方会直接编辑以前的文章内容 + """ + return post["PublishDate"] + + def get_date(self, _: RawPost) -> None: + return None + + async def parse(self, raw_post: RawPost) -> Post: + text = f'{raw_post["Title"]}\n{raw_post["Summary"]}' + url = raw_post["Author"] + return Post("ff14", text=text, url=url, target_name="最终幻想XIV官方公告") From a6a2fdb908638f3ea0ea08fa9545b98048894634 Mon Sep 17 00:00:00 2001 From: hemengyang Date: Fri, 18 Feb 2022 18:31:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=20ff14=20?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E5=85=AC=E5=91=8A=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + tests/platforms/static/ff14-newdata-0.json | 1 + tests/platforms/static/ff14-newdata-1.json | 1 + tests/platforms/test_ff14.py | 46 ++++++++++++++++++++++ tests/platforms/utils.py | 4 +- 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/platforms/static/ff14-newdata-0.json create mode 100644 tests/platforms/static/ff14-newdata-1.json create mode 100644 tests/platforms/test_ff14.py diff --git a/.gitignore b/.gitignore index 3e0a45a..8b8f3e5 100644 --- a/.gitignore +++ b/.gitignore @@ -319,3 +319,4 @@ data*/* .env.* .vim/* !dist/.gitkeep +.vscode diff --git a/tests/platforms/static/ff14-newdata-0.json b/tests/platforms/static/ff14-newdata-0.json new file mode 100644 index 0000000..d337db7 --- /dev/null +++ b/tests/platforms/static/ff14-newdata-0.json @@ -0,0 +1 @@ +{"Code":"0","Message":"","PageCount":293,"TotalCount":1465,"RecordCount":5,"Data":[{"Id":336868,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":9,"GroupIndex":0,"TitleClass":"","Title":"LIVE番外:第68回制作人来信转播 2月19日上演","Summary":"第68回制作人来信将于2022年2月19日放送,届时FFXIV的制作人兼导演吉田直树将会以「FFXIV的全新挑战 ~面向下一个10年~」为话题为大家介绍今后的更新情报。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336868","PublishDate":"2022/02/15 16:02:21","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448326143171.jpg"},{"Id":336969,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":8,"GroupIndex":0,"TitleClass":"","Title":"群狼盛宴第20赛季对战数据查询开放","Summary":"群狼盛宴第20赛季对战数据查询开放。冒险现在可以在专题页面点击右上角的「对战数据查询」来查询第20赛季的总对战场次和胜利场次数据。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336969","PublishDate":"2022/02/17 15:09:31","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450708307681.jpg"},{"Id":336870,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":7,"GroupIndex":0,"TitleClass":"","Title":"最终幻想XIV 银质坠饰 <友谊永存>预售开启!","Summary":"最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870","PublishDate":"2022/02/15 14:11:09","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448345978202.jpg"},{"Id":336869,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":6,"GroupIndex":0,"TitleClass":"","Title":"2月22日「太阳海岸」、「伊修加德」服务器临时维护公告","Summary":"我们将于2月22日14:00-16:00对豆豆柴区进行临时维护。维护结束后将开启「太阳海岸」、「伊修加德」服务器个人及部队房屋购买功能。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336869","PublishDate":"2022/02/15 16:17:13","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448330187049.jpg"},{"Id":336978,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":5,"GroupIndex":0,"TitleClass":"","Title":"《最终幻想14》2月17日违规账号处罚公告","Summary":"为了更好地维护游戏内的游戏秩序,保障各位冒险者良好公正的游戏体验,近期我们对游戏中违反了游戏规定的账号进行了查处,封号名单已更新至违规处理平台中。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336978","PublishDate":"2022/02/17 15:38:20","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450834782144.jpg"}]} \ No newline at end of file diff --git a/tests/platforms/static/ff14-newdata-1.json b/tests/platforms/static/ff14-newdata-1.json new file mode 100644 index 0000000..062f81c --- /dev/null +++ b/tests/platforms/static/ff14-newdata-1.json @@ -0,0 +1 @@ +{"Code":"0","Message":"","PageCount":293,"TotalCount":1465,"RecordCount":5,"Data":[{"Id":336868,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":9,"GroupIndex":0,"TitleClass":"","Title":"LIVE番外:第68回制作人来信转播 2月19日上演","Summary":"第68回制作人来信将于2022年2月19日放送,届时FFXIV的制作人兼导演吉田直树将会以「FFXIV的全新挑战 ~面向下一个10年~」为话题为大家介绍今后的更新情报。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336868","PublishDate":"2022/02/15 16:02:21","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448326143171.jpg"},{"Id":336969,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":8,"GroupIndex":0,"TitleClass":"","Title":"群狼盛宴第20赛季对战数据查询开放","Summary":"群狼盛宴第20赛季对战数据查询开放。冒险现在可以在专题页面点击右上角的「对战数据查询」来查询第20赛季的总对战场次和胜利场次数据。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336969","PublishDate":"2022/02/17 15:09:31","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450708307681.jpg"},{"Id":336870,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":7,"GroupIndex":0,"TitleClass":"","Title":"最终幻想XIV 银质坠饰 <友谊永存>预售开启!","Summary":"最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870","PublishDate":"2022/02/18 14:11:09","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448345978202.jpg"},{"Id":336869,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":6,"GroupIndex":0,"TitleClass":"","Title":"2月22日「太阳海岸」、「伊修加德」服务器临时维护公告","Summary":"我们将于2月22日14:00-16:00对豆豆柴区进行临时维护。维护结束后将开启「太阳海岸」、「伊修加德」服务器个人及部队房屋购买功能。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336869","PublishDate":"2022/02/15 16:17:13","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448330187049.jpg"},{"Id":336978,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":5,"GroupIndex":0,"TitleClass":"","Title":"《最终幻想14》2月17日违规账号处罚公告","Summary":"为了更好地维护游戏内的游戏秩序,保障各位冒险者良好公正的游戏体验,近期我们对游戏中违反了游戏规定的账号进行了查处,封号名单已更新至违规处理平台中。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336978","PublishDate":"2022/02/17 15:38:20","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450834782144.jpg"}]} \ No newline at end of file diff --git a/tests/platforms/test_ff14.py b/tests/platforms/test_ff14.py new file mode 100644 index 0000000..4a7d665 --- /dev/null +++ b/tests/platforms/test_ff14.py @@ -0,0 +1,46 @@ +import pytest +import respx +from httpx import Response +from nonebug.app import App + +from .utils import get_json + + +@pytest.fixture +def ff14(app: App): + from nonebot_bison.platform import platform_manager + + return platform_manager["ff14"] + + +@pytest.fixture(scope="module") +def ff14_newdata_json_0(): + return get_json("ff14-newdata-0.json") + + +@pytest.fixture(scope="module") +def ff14_newdata_json_1(): + return get_json("ff14-newdata-1.json") + + +@pytest.mark.asyncio +@respx.mock +async def test_fetch_new( + ff14, dummy_user_subinfo, ff14_newdata_json_0, ff14_newdata_json_1 +): + newdata = respx.get( + "https://ff.web.sdo.com/inc/newdata.ashx?url=List?gameCode=ff&category=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5" + ) + newdata.mock(return_value=Response(200, json=ff14_newdata_json_0)) + target = "" + res = await ff14.fetch_new_post(target, [dummy_user_subinfo]) + assert newdata.called + assert len(res) == 0 + newdata.mock(return_value=Response(200, json=ff14_newdata_json_1)) + res = await ff14.fetch_new_post(target, [dummy_user_subinfo]) + assert newdata.called + post = res[0][1][0] + assert post.target_type == "ff14" + assert post.text == "最终幻想XIV 银质坠饰 <友谊永存>预售开启!\n最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!" + assert post.url == "https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870" + assert post.target_name == "最终幻想XIV官方公告" diff --git a/tests/platforms/utils.py b/tests/platforms/utils.py index 0fd8c7b..b2adc59 100644 --- a/tests/platforms/utils.py +++ b/tests/platforms/utils.py @@ -5,12 +5,12 @@ path = Path(__file__).parent / "static" def get_json(file_name: str): - with open(path / file_name, "r") as f: + with open(path / file_name, "r", encoding="utf8") as f: file_text = f.read() return json.loads(file_text) def get_file(file_name: str): - with open(path / file_name, "r") as f: + with open(path / file_name, "r", encoding="utf8") as f: file_text = f.read() return file_text From cc375d96d78ea56a20320c2a9d43a8556e9eb72d Mon Sep 17 00:00:00 2001 From: hemengyang Date: Fri, 18 Feb 2022 20:32:57 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=80=E4=B8=8B=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 35621f42482494d642eba12f51ab25354e7ee160 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 18 Feb 2022 21:33:12 +0800 Subject: [PATCH 4/5] fix ci --- .circleci/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/main.yml b/.circleci/main.yml index 43f887c..878d32c 100644 --- a/.circleci/main.yml +++ b/.circleci/main.yml @@ -25,6 +25,7 @@ workflows: - build-frontend - test build-test-publish: + unless: << pipeline.parameters.is_pr >> jobs: - build-frontend: filters: From 6c5faaa4c46760ab7b9db479dce7294dd80da07c Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 18 Feb 2022 21:34:15 +0800 Subject: [PATCH 5/5] update change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c858311..a16e0c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,3 +57,7 @@ - 又双叒叕重构了一下 - 修复了 Docker 中 Playwright 下载的浏览器版本不正确问题 - 加入了猴子补丁,使 Windows 里能运行 Playwright + +## [0.5.0] + +- 添加了 FF14