mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
⬆️ 适配 Pydantic V2 (#484)
* ⬆️ 适配 Pydantic V2 * 🐛 修复测试报错 * 🐛 适配忘记的 from_orm * 🐛 忘记的 class-based `config` * 🐛 更新 red 适配器版本
This commit is contained in:
@@ -4,6 +4,7 @@ from functools import partial
|
||||
from httpx import AsyncClient
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from pydantic import Field, BaseModel
|
||||
from nonebot.compat import type_validate_python
|
||||
|
||||
from ..post import Post
|
||||
from ..types import Target, RawPost, Category
|
||||
@@ -28,9 +29,6 @@ class BulletinListItem(BaseModel):
|
||||
class BulletinList(BaseModel):
|
||||
list: list[BulletinListItem]
|
||||
|
||||
class Config:
|
||||
extra = "ignore"
|
||||
|
||||
|
||||
class BulletinData(BaseModel):
|
||||
cid: str
|
||||
@@ -76,7 +74,7 @@ class Arknights(NewMessage):
|
||||
|
||||
async def get_sub_list(self, _) -> list[BulletinListItem]:
|
||||
raw_data = await self.client.get("https://ak-webview.hypergryph.com/api/game/bulletinList?target=IOS")
|
||||
return ArkBulletinListResponse.parse_obj(raw_data.json()).data.list
|
||||
return type_validate_python(ArkBulletinListResponse, raw_data.json()).data.list
|
||||
|
||||
def get_id(self, post: BulletinListItem) -> Any:
|
||||
return post.cid
|
||||
@@ -95,7 +93,7 @@ class Arknights(NewMessage):
|
||||
raw_data = await self.client.get(
|
||||
f"https://ak-webview.hypergryph.com/api/game/bulletin/{self.get_id(post=raw_post)}"
|
||||
)
|
||||
data = ArkBulletinResponse.parse_obj(raw_data.json()).data
|
||||
data = type_validate_python(ArkBulletinResponse, raw_data.json()).data
|
||||
|
||||
def title_escape(text: str) -> str:
|
||||
return text.replace("\\n", " - ")
|
||||
|
||||
@@ -9,6 +9,9 @@ from datetime import datetime, timedelta
|
||||
from httpx import AsyncClient
|
||||
from nonebot.log import logger
|
||||
from pydantic import Field, BaseModel
|
||||
from nonebot.compat import type_validate_python
|
||||
|
||||
from nonebot_bison.compat import model_rebuild
|
||||
|
||||
from ..post import Post
|
||||
from ..utils import SchedulerConfig, text_similarity
|
||||
@@ -303,7 +306,7 @@ class Bilibililive(StatusChange):
|
||||
infos = []
|
||||
for target in targets:
|
||||
if target in data.keys():
|
||||
infos.append(self.Info.parse_obj(data[target]))
|
||||
infos.append(type_validate_python(self.Info, data[target]))
|
||||
else:
|
||||
infos.append(self._gen_empty_info(int(target)))
|
||||
return infos
|
||||
@@ -428,4 +431,4 @@ class BilibiliBangumi(StatusChange):
|
||||
)
|
||||
|
||||
|
||||
Bilibililive.Info.update_forward_refs()
|
||||
model_rebuild(Bilibililive.Info)
|
||||
|
||||
Reference in New Issue
Block a user