Skip to content

Commit

Permalink
refactor: 类“BaseModel”中的“dict”方法已弃用
Browse files Browse the repository at this point in the history
dict() -> model_dump()
  • Loading branch information
Johnserf-Seed committed Apr 11, 2024
1 parent 53e00c7 commit ed766bd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/snippets/douyin/xbogus.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def main():

async def gen_user_profile(params: UserProfile):
return XBogusManager.model_2_endpoint(
dyendpoint.USER_DETAIL, params.dict()
dyendpoint.USER_DETAIL, params.model_dump()
)

async def main():
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/tiktok/xbogus.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def main():

async def gen_user_profile(params: UserProfile):
return XBogusManager.model_2_endpoint(
tkendpoint.USER_DETAIL, params.dict()
tkendpoint.USER_DETAIL, params.model_dump()
)

async def main():
Expand Down
48 changes: 24 additions & 24 deletions f2/apps/douyin/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def fetch_user_profile(self, params: UserProfile):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_DETAIL,
params.dict(),
params.model_dump(),
)
logger.debug(_("用户信息接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -62,7 +62,7 @@ async def fetch_user_post(self, params: UserPost):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_POST,
params.dict(),
params.model_dump(),
)
logger.debug(_("主页作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -71,7 +71,7 @@ async def fetch_user_like(self, params: UserLike):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_FAVORITE_A,
params.dict(),
params.model_dump(),
)
logger.debug(_("主页喜欢作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -80,16 +80,16 @@ async def fetch_user_collection(self, params: UserCollection):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_COLLECTION,
params.dict(),
params.model_dump(),
)
logger.debug(_("主页收藏作品接口地址:{0}").format(endpoint))
return await self._fetch_post_json(endpoint, params.dict())
return await self._fetch_post_json(endpoint, params.model_dump())

async def fetch_user_collects(self, params: UserCollects):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_COLLECTS,
params.dict(),
params.model_dump(),
)
logger.debug(_("收藏夹接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -98,7 +98,7 @@ async def fetch_user_collects_video(self, params: UserCollectsVideo):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_COLLECTS_VIDEO,
params.dict(),
params.model_dump(),
)
logger.debug(_("收藏夹作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -107,7 +107,7 @@ async def fetch_user_music_collection(self, params: UserMusicCollection):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_MUSIC_COLLECTION,
params.dict(),
params.model_dump(),
)
logger.debug(_("音乐收藏接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -116,7 +116,7 @@ async def fetch_user_mix(self, params: UserMix):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.MIX_AWEME,
params.dict(),
params.model_dump(),
)
logger.debug(_("合集作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -125,7 +125,7 @@ async def fetch_post_detail(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.POST_DETAIL,
params.dict(),
params.model_dump(),
)
logger.debug(_("作品详情接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -134,7 +134,7 @@ async def fetch_post_comment(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.POST_COMMENT,
params.dict(),
params.model_dump(),
)
logger.debug(_("作品评论接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -143,7 +143,7 @@ async def fetch_post_feed(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.TAB_FEED,
params.dict(),
params.model_dump(),
)
logger.debug(_("首页推荐作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -152,7 +152,7 @@ async def fetch_follow_feed(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.FOLLOW_FEED,
params.dict(),
params.model_dump(),
)
logger.debug(_("关注作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -161,7 +161,7 @@ async def fetch_friend_feed(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.FRIEND_FEED,
params.dict(),
params.model_dump(),
)
logger.debug(_("朋友作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -170,7 +170,7 @@ async def fetch_post_related(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.POST_RELATED,
params.dict(),
params.model_dump(),
)
logger.debug(_("相关推荐作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -179,7 +179,7 @@ async def fetch_live(self, params: UserLive):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.LIVE_INFO,
params.dict(),
params.model_dump(),
)
logger.debug(_("直播接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -192,7 +192,7 @@ async def fetch_live_room_id(self, params: UserLive2):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.LIVE_INFO_ROOM_ID,
params.dict(),
params.model_dump(),
)
logger.debug(_("直播接口地址(room_id):{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -203,7 +203,7 @@ async def fetch_follow_live(self, params: FollowUserLive):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.FOLLOW_USER_LIVE,
params.dict(),
params.model_dump(),
)
logger.debug(_("关注用户直播接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -212,7 +212,7 @@ async def fetch_locate_post(self, params: UserPost):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.LOCATE_POST,
params.dict(),
params.model_dump(),
)
logger.debug(_("定位上一次作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -221,7 +221,7 @@ async def fetch_login_qrcode(self, parms: LoginGetQr):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.SSO_LOGIN_GET_QR,
parms.dict(),
parms.model_dump(),
)
logger.debug(_("SSO获取二维码接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -230,7 +230,7 @@ async def fetch_check_qrcode(self, parms: LoginCheckQr):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.SSO_LOGIN_CHECK_QR,
parms.dict(),
parms.model_dump(),
)
logger.debug(_("SSO检查扫码状态接口地址:{0}").format(endpoint))
return await self._fetch_response(endpoint)
Expand All @@ -239,7 +239,7 @@ async def fetch_check_login(self, parms: LoginCheckQr):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.SSO_LOGIN_CHECK_LOGIN,
parms.dict(),
parms.model_dump(),
)
logger.debug(_("SSO检查登录状态接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -248,7 +248,7 @@ async def fetch_user_following(self, params: UserFollowing):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_FOLLOWING,
params.dict(),
params.model_dump(),
)
logger.debug(_("用户关注列表接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -257,7 +257,7 @@ async def fetch_user_follower(self, params: UserFollower):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
dyendpoint.USER_FOLLOWER,
params.dict(),
params.model_dump(),
)
logger.debug(_("用户粉丝列表接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand Down
2 changes: 1 addition & 1 deletion f2/apps/douyin/test/test_apps_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_xbogus_manager():
final_endpoint = XBogusManager.model_2_endpoint(
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
base_endpoint=dyendpoint.USER_DETAIL,
params=params.dict(),
params=params.model_dump(),
)

assert final_endpoint, "Failed to get a final endpoint."
18 changes: 9 additions & 9 deletions f2/apps/tiktok/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def fetch_user_profile(self, params: UserProfile):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.USER_DETAIL,
params.dict(),
params.model_dump(),
)
logger.debug(_("用户信息接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -54,7 +54,7 @@ async def fetch_user_post(self, params: UserPost):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.USER_POST,
params.dict(),
params.model_dump(),
)
logger.debug(_("主页作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -63,7 +63,7 @@ async def fetch_user_like(self, params: UserLike):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.USER_LIKE,
params.dict(),
params.model_dump(),
)
logger.debug(_("喜欢作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -72,7 +72,7 @@ async def fetch_user_collect(self, params: UserCollect):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.USER_COLLECT,
params.dict(),
params.model_dump(),
)
logger.debug(_("收藏作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -81,7 +81,7 @@ async def fetch_user_play_list(self, params: UserPlayList):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.USER_PLAY_LIST,
params.dict(),
params.model_dump(),
)
logger.debug(_("合辑列表接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -90,7 +90,7 @@ async def fetch_user_mix(self, params: UserMix):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.USER_MIX,
params.dict(),
params.model_dump(),
)
logger.debug(_("合辑作品接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -99,7 +99,7 @@ async def fetch_post_detail(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.AWEME_DETAIL,
params.dict(),
params.model_dump(),
)
logger.debug(_("作品详情接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -108,7 +108,7 @@ async def fetch_post_comment(self, params: PostComment):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.POST_COMMENT,
params.dict(),
params.model_dump(),
)
logger.debug(_("作品评论接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand All @@ -117,7 +117,7 @@ async def fetch_post_recommend(self, params: PostDetail):
endpoint = XBogusManager.model_2_endpoint(
self.headers.get("User-Agent"),
tkendpoint.HOME_RECOMMEND,
params.dict(),
params.model_dump(),
)
logger.debug(_("首页推荐接口地址:{0}").format(endpoint))
return await self._fetch_get_json(endpoint)
Expand Down

0 comments on commit ed766bd

Please sign in to comment.