diff options
author | Kyomotoi <[email protected]> | 2022-10-04 13:25:33 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2022-10-04 13:25:33 +0800 |
commit | 43a8d02c4122a0d236c5cbd7b773a8c77715b244 (patch) | |
tree | 702721f743f5505be8a60c4be0449ce0455cd3a2 | |
parent | 2fdfe6513efb98847b01027ae7d32cae43ae77f2 (diff) | |
download | ATRI-43a8d02c4122a0d236c5cbd7b773a8c77715b244.tar.gz ATRI-43a8d02c4122a0d236c5cbd7b773a8c77715b244.tar.bz2 ATRI-43a8d02c4122a0d236c5cbd7b773a8c77715b244.zip |
🎨 优化代码
-rw-r--r-- | ATRI/plugins/rss/rss_rsshub/__init__.py | 10 | ||||
-rw-r--r-- | ATRI/plugins/rss/rss_rsshub/data_source.py | 16 |
2 files changed, 10 insertions, 16 deletions
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( |