44
55import httpx
66from httpx import URL , Timeout
7- from pydantic_extra_types .country import CountryAlpha2
87
8+ from ctftime_api .models .country import CountryCode
99from ctftime_api .models .event import Event , EventResult
10- from ctftime_api .models .team import TeamRank , Team , TeamComplete
10+ from ctftime_api .models .team import Team , TeamComplete , TeamRank
1111from ctftime_api .models .vote import Vote
1212
1313__all__ = ["CTFTimeClient" ]
@@ -65,10 +65,10 @@ async def get_top_teams_per_year(
6565 response : dict [str , list [dict ]] = await self ._get (url , params = {"limit" : limit })
6666 teams = response .get (f"{ year } " , [])
6767
68- return [TeamRank .model_validate (team ) for team in teams ]
68+ return [TeamRank .from_dict (team ) for team in teams ]
6969
7070 async def get_top_team_by_country (
71- self , country : str | CountryAlpha2
71+ self , country : str | CountryCode
7272 ) -> list [TeamRank ]:
7373 """
7474 Get the top teams in the leaderboard for a specific country.
@@ -78,9 +78,7 @@ async def get_top_team_by_country(
7878 :raise httpx.HTTPStatusError: If the response status code is not successful.
7979 :raise ValueError: If the country is not a two-letter country code or a pycountry Country object.
8080 """
81- if isinstance (country , CountryAlpha2 ):
82- country = country
83- elif isinstance (country , str ):
81+ if isinstance (country , str ):
8482 if len (country ) != 2 :
8583 raise ValueError (
8684 "Country must be a two-letter country code or a pycountry Country object."
@@ -89,7 +87,7 @@ async def get_top_team_by_country(
8987 url = self ._base_url .join ("top-by-country/" ).join (f"{ country } /" )
9088 teams : list [dict [str , Any ]] = await self ._get (url )
9189
92- return [TeamRank .model_validate (team ) for team in teams ]
90+ return [TeamRank .from_dict (team ) for team in teams ]
9391
9492 async def get_events_information (
9593 self , start : int | datetime , end : int | datetime , limit : int = 10
@@ -118,7 +116,7 @@ async def get_events_information(
118116 url , params = {"start" : start , "finish" : end , "limit" : limit }
119117 )
120118
121- return [Event .model_validate (event ) for event in events ]
119+ return [Event .from_dict (event ) for event in events ]
122120
123121 async def get_event_information (self , event_id : int ) -> Event :
124122 """
@@ -130,7 +128,7 @@ async def get_event_information(self, event_id: int) -> Event:
130128 url = self ._base_url .join (f"events/{ event_id } /" )
131129 event : dict [str , Any ] = await self ._get (url )
132130
133- return Event .model_validate (event )
131+ return Event .from_dict (event )
134132
135133 async def get_teams_information (
136134 self , limit : int = 100 , offset : int = 0
@@ -149,7 +147,7 @@ async def get_teams_information(
149147 )
150148 teams : list [dict [str , Any ]] = response .get ("results" , [])
151149
152- return [Team .model_validate (team ) for team in teams ]
150+ return [Team .from_dict (team ) for team in teams ]
153151
154152 async def get_team_information (self , team_id : int ) -> TeamComplete :
155153 """
@@ -161,7 +159,7 @@ async def get_team_information(self, team_id: int) -> TeamComplete:
161159 url = self ._base_url .join (f"teams/{ team_id } /" )
162160 team : dict [str , Any ] = await self ._get (url )
163161
164- return TeamComplete .model_validate (team )
162+ return TeamComplete .from_dict (team )
165163
166164 async def get_event_results (
167165 self , year : int | None = None
@@ -181,7 +179,7 @@ async def get_event_results(
181179 event : dict [str , dict ] = await self ._get (url )
182180
183181 return {
184- int (ctf_id ): EventResult ( ** result , ctf_id = int ( ctf_id ) )
182+ int (ctf_id ): EventResult . from_dict ( result )
185183 for ctf_id , result in event .items ()
186184 }
187185
@@ -206,4 +204,4 @@ async def get_votes_per_year(
206204 url = self ._base_url .join (f"votes/{ year } /" )
207205 votes : list [dict ] = await self ._get (url , timeout = timeout )
208206
209- return [Vote ( ** vote ) for vote in votes ]
207+ return [Vote . from_dict ( vote ) for vote in votes ]
0 commit comments