From 43a8d02c4122a0d236c5cbd7b773a8c77715b244 Mon Sep 17 00:00:00 2001 From: Kyomotoi <0w0@imki.moe> Date: Tue, 4 Oct 2022 13:25:33 +0800 Subject: =?UTF-8?q?=F0=9F=8E=A8=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/rss/rss_rsshub/__init__.py | 10 +++++----- ATRI/plugins/rss/rss_rsshub/data_source.py | 16 +++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'ATRI') diff --git a/ATRI/plugins/rss/rss_rsshub/__init__.py b/ATRI/plugins/rss/rss_rsshub/__init__.py index 2d23f16..eaac2e7 100644 --- a/ATRI/plugins/rss/rss_rsshub/__init__.py +++ b/ATRI/plugins/rss/rss_rsshub/__init__.py @@ -57,7 +57,7 @@ async def _(event: GroupMessageEvent): subs.append([i._id, i.title]) output = "本群的 RSSHub 订阅列表如下~\n" + tabulate( - subs, headers=["ID", "title"], tablefmt="plain" + subs, headers=["ID", "Title"], tablefmt="plain" ) await del_sub.send(output) @@ -95,7 +95,7 @@ async def _(event: GroupMessageEvent): output = "本群的 RSSHub 订阅列表如下~\n" + tabulate( subs, headers=["最后更新时间", "标题"], tablefmt="plain" ) - await get_sub_list.send(output) + await get_sub_list.finish(output) tq = asyncio.Queue() @@ -104,15 +104,15 @@ tq = asyncio.Queue() class RssHubDynamicChecker(BaseTrigger): def get_next_fire_time(self, previous_fire_time, now): conf = RssHubSubscriptor().load_service("rss.rsshub") - if conf["enabled"]: + if conf.get("enabled"): return now @scheduler.scheduled_job( AndTrigger([IntervalTrigger(seconds=120), RssHubDynamicChecker()]), name="RssHub 订阅检查", - max_instances=3, # type: ignore - misfire_grace_time=60, # type: ignore + max_instances=3, + misfire_grace_time=60, ) async def _(): sub = RssHubSubscriptor() diff --git a/ATRI/plugins/rss/rss_rsshub/data_source.py b/ATRI/plugins/rss/rss_rsshub/data_source.py index 0dc0ebd..ca6f80c 100644 --- a/ATRI/plugins/rss/rss_rsshub/data_source.py +++ b/ATRI/plugins/rss/rss_rsshub/data_source.py @@ -58,17 +58,11 @@ class RssHubSubscriptor(Service): raise RssError("rss.rsshub: 获取所有订阅失败") async def add_sub(self, url: str, group_id: int) -> str: - try: - resp = await request.get(url) - except Exception: - raise RssError("rss.rsshub: 请求链接失败") - - if "RSSHub" not in resp.text: + data = await self.get_rsshub_info(url) + if not data: return "该链接不含RSSHub内容" - xml_data = resp.read() - data = xmltodict.parse(xml_data) - check_url = data["rss"]["channel"]["link"] + check_url = data["link"] query_result = await self.get_sub_list( {"raw_link": check_url, "group_id": group_id} @@ -78,8 +72,8 @@ class RssHubSubscriptor(Service): return f"该链接已经订阅过啦! ID: {_id}" _id = gen_random_str(6) - title = data["rss"]["channel"]["title"] - disc = data["rss"]["channel"]["description"] + title = data["title"] + disc = data["description"] await self.__add_sub(_id, group_id) await self.update_sub( -- cgit v1.2.3