From 33a969e78232bc873a9037aa144e6cec45d6ff29 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Wed, 3 Mar 2021 20:36:48 +0800 Subject: [PATCH] add retry --- src/plugins/nonebot_hk_reporter/platform/platform.py | 10 +++++++++- src/plugins/nonebot_hk_reporter/platform/weibo.py | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/plugins/nonebot_hk_reporter/platform/platform.py b/src/plugins/nonebot_hk_reporter/platform/platform.py index 8576dfe..e1b30e0 100644 --- a/src/plugins/nonebot_hk_reporter/platform/platform.py +++ b/src/plugins/nonebot_hk_reporter/platform/platform.py @@ -208,7 +208,15 @@ class PlatformNoTarget(PlatformProto): async def _parse_with_cache(self, post: RawPost) -> Post: post_id = self.get_id(post) if post_id not in self.cache: - self.cache[post_id] = await self.parse(post) + retry_times = 3 + while retry_times: + try: + self.cache[post_id] = await self.parse(post) + break + except Exception as err: + if not retry_times: + raise err + retry_times -= 1 return self.cache[post_id] async def filter_common(self, raw_post_list: list[RawPost]) -> list[RawPost]: diff --git a/src/plugins/nonebot_hk_reporter/platform/weibo.py b/src/plugins/nonebot_hk_reporter/platform/weibo.py index f120fc8..bed3d0e 100644 --- a/src/plugins/nonebot_hk_reporter/platform/weibo.py +++ b/src/plugins/nonebot_hk_reporter/platform/weibo.py @@ -89,6 +89,8 @@ class Weibo(Platform): await super().filter_common(target, raw_post_list) return [] else: + if not raw_post_list: + return [] new_post = self._get_top(raw_post_list) res = await super().filter_common(target, raw_post_list) if (self.top[target] is not None and new_post is None) or \