Merge pull request #96 from felinae98/status-change-error

在StatusChange中提供了如果api返回错误不更新status的方法
This commit is contained in:
felinae98 2022-07-31 23:24:38 +08:00 committed by GitHub
commit 0c8ff2dfc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -201,7 +201,7 @@ class Bilibililive(StatusChange):
info["cover"] = res_dict["data"]["live_room"]["cover"]
return info
else:
return []
raise self.ParseTargetException(res.text)
def compare_status(self, target: Target, old_status, new_status) -> list[RawPost]:
if (

View File

@ -268,6 +268,9 @@ class NewMessage(MessageProcess, abstract=True):
class StatusChange(Platform, abstract=True):
"Watch a status, and fire a post when status changes"
class FetchError(RuntimeError):
pass
@abstractmethod
async def get_status(self, target: Target) -> Any:
...
@ -283,7 +286,11 @@ class StatusChange(Platform, abstract=True):
async def fetch_new_post(
self, target: Target, users: list[UserSubInfo]
) -> list[tuple[User, list[Post]]]:
new_status = await self.get_status(target)
try:
new_status = await self.get_status(target)
except self.FetchError as err:
logger.warning(f"fetching {self.name}-{target} error: {err}")
return []
res = []
if old_status := self.get_stored_data(target):
diff = self.compare_status(target, old_status, new_status)