💥 🗃️ 将 pydantic 模型序列化后再存数据库

This commit is contained in:
2023-11-21 20:47:56 +08:00
parent 60605d0dca
commit 1e02858913
4 changed files with 135 additions and 10 deletions

View File

@@ -130,9 +130,9 @@ class Processor(ProcessorMeta):
"""获取用户数据"""
if other_parameter is None:
other_parameter = {}
fset: frozenset[tuple[str, str | bytes]] = frozenset(other_parameter.items())
if self.processed_data.user_profile.get(fset) is None:
self.raw_response.user_profile[fset] = await Request.request(
params = urlencode(dict(sorted(other_parameter.items())))
if self.processed_data.user_profile.get(params) is None:
self.raw_response.user_profile[params] = await Request.request(
splice_url(
[
BASE_URL,
@@ -141,8 +141,8 @@ class Processor(ProcessorMeta):
]
)
)
self.processed_data.user_profile[fset] = UserProfile.parse_raw(self.raw_response.user_profile[fset])
return self.processed_data.user_profile[fset]
self.processed_data.user_profile[params] = UserProfile.parse_raw(self.raw_response.user_profile[params])
return self.processed_data.user_profile[params]
async def get_game_data(self) -> GameData | None:
"""获取游戏数据"""

View File

@@ -4,10 +4,10 @@ from .user_profile import UserProfile
class RawResponse(BaseRawResponse):
user_profile: dict[frozenset[tuple[str, str | bytes]], bytes]
user_profile: dict[str, bytes]
user_info: bytes | None = None
class ProcessedData(BaseProcessedData):
user_profile: dict[frozenset[tuple[str, str | bytes]], UserProfile]
user_profile: dict[str, UserProfile]
user_info: InfoSuccess | None = None