@@ -40,11 +40,12 @@ def __init__(
4040 async def __aenter__ (self ) -> 'NetSchoolAPI' :
4141 return self
4242
43- async def __aexit__ (self , exc_type , exc_val , exc_tb ):
43+ async def __aexit__ (self , _exc_type , _exc_val , _exc_tb ):
4444 await self .logout ()
4545
4646 async def login (
47- self , user_name : str , password : str , school : str ,
47+ self , user_name : str , password : str ,
48+ school_name_or_id : Union [int , str ],
4849 requests_timeout : int = None ):
4950 requester = self ._wrapped_client .make_requester (requests_timeout )
5051 # Getting the `NSSESSIONID` cookie for `auth/getdata`
@@ -66,7 +67,7 @@ async def login(
6667 'login' ,
6768 data = {
6869 'loginType' : 1 ,
69- ** (await self ._address (school , requester )),
70+ ** (await self ._address (school_name_or_id , requester )),
7071 'un' : user_name ,
7172 'pw' : pw ,
7273 'pw2' : pw2 ,
@@ -112,7 +113,7 @@ async def login(
112113 assignment ['id' ]: assignment ['name' ]
113114 for assignment in assignment_reference
114115 }
115- self ._login_data = (user_name , password , school )
116+ self ._login_data = (user_name , password , school_name_or_id )
116117
117118 async def _request_with_optional_relogin (
118119 self , requests_timeout : Optional [int ], path : str ,
@@ -194,7 +195,8 @@ async def diary(
194195 )
195196 diary_schema = schemas .Diary ()
196197 diary_schema .context ['assignment_types' ] = self ._assignment_types
197- return diary_schema .load (response .json ())
198+ diary = diary_schema .load (response .json ())
199+ return diary # type: ignore
198200
199201 async def overdue (
200202 self ,
@@ -221,7 +223,7 @@ async def overdue(
221223 assignments_schema = schemas .Assignment ()
222224 assignments_schema .context ['assignment_types' ] = self ._assignment_types
223225 assignments = assignments_schema .load (response .json (), many = True )
224- return assignments
226+ return assignments # type: ignore
225227
226228 async def announcements (
227229 self , take : Optional [int ] = - 1 ,
@@ -232,7 +234,7 @@ async def announcements(
232234 params = {'take' : take },
233235 )
234236 announcements = schemas .Announcement ().load (response .json (), many = True )
235- return announcements
237+ return announcements # type: ignore
236238
237239 async def attachments (
238240 self , assignment_id : int ,
@@ -249,15 +251,15 @@ async def attachments(
249251 return []
250252 attachments_json = response [0 ]['attachments' ]
251253 attachments = schemas .Attachment ().load (attachments_json , many = True )
252- return attachments
254+ return attachments # type: ignore
253255
254256 async def school (self , requests_timeout : int = None ) -> schemas .School :
255257 response = await self ._request_with_optional_relogin (
256258 requests_timeout ,
257259 'schools/{0}/card' .format (self ._school_id ),
258260 )
259261 school = schemas .School ().load (response .json ())
260- return school
262+ return school # type: ignore
261263
262264 async def logout (self , requests_timeout : int = None ):
263265 try :
@@ -282,20 +284,26 @@ async def full_logout(self, requests_timeout: int = None):
282284 await self .logout (requests_timeout )
283285 await self ._wrapped_client .client .aclose ()
284286
287+ async def schools (
288+ self , requests_timeout : int = None ) -> List [schemas .ShortSchool ]:
289+ resp = await self ._wrapped_client .request (requests_timeout , "addresses/schools" )
290+ schools = schemas .ShortSchool ().load (resp .json (), many = True )
291+ return schools # type: ignore
292+
285293 async def _address (
286- self , school : str , requester : Requester ) -> Dict [str , int ]:
287- response = await requester ('addresses/schools' )
294+ self , school_name_or_id : Union [int , str ],
295+ requester : Requester ) -> Dict [str , int ]:
296+ schools = (await requester ("addresses/schools" )).json ()
288297
289- schools_reference = response .json ()
290- for school_ in schools_reference :
291- if school_ ['name' ] == school or school_ ['id' ] == school :
292- self ._school_id = school_ ['id' ]
298+ for school in schools :
299+ if school ["name" ] == school_name_or_id or school ["id" ] == school_name_or_id :
300+ self ._school_id = school ['id' ]
293301 return {
294- 'cid' : school_ ['countryId' ],
295- 'sid' : school_ ['stateId' ],
296- 'pid' : school_ ['municipalityDistrictId' ],
297- 'cn' : school_ ['cityId' ],
302+ 'cid' : school ['countryId' ],
303+ 'sid' : school ['stateId' ],
304+ 'pid' : school ['municipalityDistrictId' ],
305+ 'cn' : school ['cityId' ],
298306 'sft' : 2 ,
299- 'scid' : school_ ['id' ],
307+ 'scid' : school ['id' ],
300308 }
301- raise errors .SchoolNotFoundError (school )
309+ raise errors .SchoolNotFoundError (school_name_or_id )
0 commit comments