librus_apix.client

This module provides classes and functions for managing API tokens, handling HTTP operations, and creating client instances for interacting with the Librus API.

Classes: - Token: A class to manage and store API tokens. - Client: A class to handle HTTP operations using tokens.

Functions: - new_client: Function to create a new instance of the Client class.

Usage:

my_client: Client = new_client()
_token: Token = my_client.get_token(username, password) # update the client token


#Alternatively, you can use the classes directly:
my_token = Token(API_Key="your_api_key")
my_client = Client(token=my_token)
  1"""
  2
  3This module provides classes and functions for managing API tokens, handling HTTP operations, and creating client instances for interacting with the Librus API.
  4
  5Classes:
  6    - Token: A class to manage and store API tokens.
  7    - Client: A class to handle HTTP operations using tokens.
  8
  9Functions:
 10    - new_client: Function to create a new instance of the Client class.
 11
 12Usage:
 13```python
 14my_client: Client = new_client()
 15_token: Token = my_client.get_token(username, password) # update the client token
 16
 17
 18#Alternatively, you can use the classes directly:
 19my_token = Token(API_Key="your_api_key")
 20my_client = Client(token=my_token)
 21```
 22"""
 23
 24from typing import Dict, Optional
 25
 26from requests import Session
 27from requests.models import Response
 28from requests.sessions import RequestsCookieJar
 29from requests.utils import cookiejar_from_dict, dict_from_cookiejar
 30
 31import librus_apix.urls as urls
 32from librus_apix.exceptions import AuthorizationError, MaintananceError, TokenKeyError
 33
 34
 35class Token:
 36    """
 37     A class to manage and store API tokens.
 38
 39    The API key should be formatted as "{DZIENNIKSID}:{SDZIENNIKSID}".
 40
 41    Attributes:
 42        API_Key (str): The combined API key.
 43        csrf_token (str): CSRF token for the session.
 44        oauth (str): OAuth token for the session.
 45
 46    Methods:
 47        _parse_api_key(API_Key: str) -> dict:
 48            Parses the API key and returns a dictionary with the tokens used for cookies.
 49        Raises:
 50            TokenKeyError: If the API_Key is not in the correct format.
 51    """
 52
 53    def __init__(
 54        self,
 55        API_Key: Optional[str] = None,
 56        dzienniks: Optional[str] = None,
 57        sdzienniks: Optional[str] = None,
 58    ):
 59        """
 60        Initializes the Token object with the given API key or token parts.
 61
 62        Args:
 63            API_Key (str, optional): The API key in the format 'DZIENNIKSID:SDZIENNIKSID'. Defaults to None.
 64            dzienniks (str, optional): The first part of the API key. Defaults to None / Ignored if API_Key is passed.
 65            sdzienniks (str, optional): The second part of the API key. Defaults to None / Ignored if API_Key is passed.
 66        """
 67        if API_Key:
 68            key = API_Key
 69        elif dzienniks and sdzienniks:
 70            key = f"{dzienniks}:{sdzienniks}"
 71        else:
 72            key = ""
 73
 74        self.API_Key = key
 75        self.csrf_token = ""
 76        self.oauth = ""
 77
 78    def __repr__(self) -> str:
 79        """
 80        Returns a string representation of the API Key.
 81
 82        Returns:
 83            str: A string representation of the API Key.
 84        """
 85        return self.API_Key
 86
 87    def _parse_api_key(self, API_Key: str) -> dict:
 88        """
 89        Parses the API Key string into a dictionary.
 90
 91        The API Key string should be in the format 'DZIENNIKSID:SDZIENNIKSID'.
 92
 93        Args:
 94            API_Key (str): The API Key string to be parsed.
 95
 96        Returns:
 97            dict: A dictionary containing the parsed API Key, with keys 'DZIENNIKSID' and 'SDZIENNIKSID'.
 98
 99        Raises:
100            TokenKeyError: If the API Key is not in the correct format.
101        """
102        parts = API_Key.split(":")
103        if len(parts) != 2:
104            raise TokenKeyError(
105                "API_Key must be in the format 'DZIENNIKSID:SDZIENNIKSID'"
106            )
107        return {"DZIENNIKSID": parts[0], "SDZIENNIKSID": parts[1]}
108
109    def access_cookies(self) -> RequestsCookieJar:
110        """
111        returns CookieJar containing authorization cookies.
112
113        Returns:
114            RequestsCookieJar: A CookieJar containing the authorization cookies generated from the parsed API Key.
115        """
116        return cookiejar_from_dict(self._parse_api_key(self.API_Key))
117
118
119class Client:
120    """
121    A class to handle HTTP operations using the tokens.
122
123    Attributes:
124        token (Token): The Token object containing the API key and tokens.
125        proxy (dict): The proxy settings for the session.
126        BASE_URL (str): The base URL for the site.
127        API_URL (str): The API URL.
128        GRADES_URL (str): The URL for grades.
129        TIMETABLE_URL (str): The URL for the timetable.
130        ANNOUNCEMENTS_URL (str): The URL for announcements.
131        MESSAGE_URL (str): The URL for messages.
132        SEND_MESSAGE_URL (str): The URL for sending messages.
133        ATTENDANCE_URL (str): The URL for attendance.
134        ATTENDANCE_DETAILS_URL (str): The URL for attendance details.
135        SCHEDULE_URL (str): The URL for the schedule.
136        HOMEWORK_URL (str): The URL for homework.
137        HOMEWORK_DETAILS_URL (str): The URL for homework details.
138        INFO_URL (str): The URL for information.
139        COMPLETED_LESSONS_URL (str): The URL for completed lessons.
140        GATEWAY_API_ATTENDANCE (str): The URL for gateway API attendance.
141        RECIPIENTS_URL (str): The URL for recipients.
142        RECIPIENT_GROUPS_URL (str): The URL for recipient groups.
143        INDEX_URL (str): Url for student index
144        cookies (RequestsCookieJar): additional cookies
145        _session (Session): The requests session for making HTTP calls.
146
147    Methods:
148        refresh_oauth() -> str:
149            Refreshes the OAuth token then returns it.
150        post(url: str, data: Dict[str, str]) -> Response:
151            Makes a POST request to the specified URL with the given data.
152        get(url: str) -> Response:
153            Makes a GET request to the specified URL.
154    """
155
156    def __init__(
157        self,
158        token: Token,
159        base_url: str = urls.BASE_URL,
160        api_url: str = urls.API_URL,
161        grades_url: str = urls.GRADES_URL,
162        timetable_url: str = urls.TIMETABLE_URL,
163        announcements_url: str = urls.ANNOUNCEMENTS_URL,
164        message_url: str = urls.MESSAGE_URL,
165        send_message_url: str = urls.SEND_MESSAGE_URL,
166        attendance_url: str = urls.ATTENDANCE_URL,
167        attendance_details_url: str = urls.ATTENDANCE_DETAILS_URL,
168        schedule_url: str = urls.SCHEDULE_URL,
169        recent_schedule_url: str = urls.RECENT_SCHEDULE_URL,
170        homework_url: str = urls.HOMEWORK_URL,
171        homework_details_url: str = urls.HOMEWORK_DETAILS_URL,
172        info_url: str = urls.INFO_URL,
173        recipients_url: str = urls.RECIPIENTS_URL,
174        recipient_groups_url: str = urls.RECIPIENT_GROUPS_URL,
175        completed_lessons_url: str = urls.COMPLETED_LESSONS_URL,
176        gateway_api_attendance: str = urls.GATEWAY_API_ATTENDANCE,
177        refresh_oauth_url: str = urls.REFRESH_OAUTH_URL,
178        index_url: str = urls.INDEX_URL,
179        proxy: Dict[str, str] = {},
180        extra_cookies: RequestsCookieJar = RequestsCookieJar(),
181    ):
182        self.token = token
183        self.proxy = proxy
184        self.BASE_URL = base_url
185        self.API_URL = api_url
186        self.GRADES_URL = grades_url
187        self.TIMETABLE_URL = timetable_url
188        self.ANNOUNCEMENTS_URL = announcements_url
189        self.MESSAGE_URL = message_url
190        self.SEND_MESSAGE_URL = send_message_url
191        self.ATTENDANCE_URL = attendance_url
192        self.ATTENDANCE_DETAILS_URL = attendance_details_url
193        self.SCHEDULE_URL = schedule_url
194        self.RECENT_SCHEDULE_URL = recent_schedule_url
195        self.HOMEWORK_URL = homework_url
196        self.HOMEWORK_DETAILS_URL = homework_details_url
197        self.INFO_URL = info_url
198        self.COMPLETED_LESSONS_URL = completed_lessons_url
199        self.GATEWAY_API_ATTENDANCE = gateway_api_attendance
200        self.RECIPIENTS_URL = recipients_url
201        self.RECIPIENT_GROUPS_URL = recipient_groups_url
202        self.REFRESH_URL = refresh_oauth_url
203        self.INDEX_URL = index_url
204        self.cookies = extra_cookies
205        self._session = Session()
206        """
207        Initializes a new instance of Client.
208
209        Args:
210            token (Token): The authentication token required for API access.
211            base_url (str, optional): The base URL of the API. Defaults to urls.BASE_URL.
212            api_url (str, optional): The URL of the API endpoint. Defaults to urls.API_URL.
213            grades_url (str, optional): The URL of the grades endpoint. Defaults to urls.GRADES_URL.
214            timetable_url (str, optional): The URL of the timetable endpoint. Defaults to urls.TIMETABLE_URL.
215            announcements_url (str, optional): The URL of the announcements endpoint. Defaults to urls.ANNOUNCEMENTS_URL.
216            message_url (str, optional): The URL of the message endpoint. Defaults to urls.MESSAGE_URL.
217            send_message_url (str, optional): The URL of the send message endpoint. Defaults to urls.SEND_MESSAGE_URL.
218            attendance_url (str, optional): The URL of the attendance endpoint. Defaults to urls.ATTENDANCE_URL.
219            attendance_details_url (str, optional): The URL of the attendance details endpoint. Defaults to urls.ATTENDANCE_DETAILS_URL.
220            schedule_url (str, optional): The URL of the schedule endpoint. Defaults to urls.SCHEDULE_URL.
221            homework_url (str, optional): The URL of the homework endpoint. Defaults to urls.HOMEWORK_URL.
222            homework_details_url (str, optional): The URL of the homework details endpoint. Defaults to urls.HOMEWORK_DETAILS_URL.
223            info_url (str, optional): The URL of the info endpoint. Defaults to urls.INFO_URL.
224            recipients_url (str, optional): The URL of the recipients endpoint. Defaults to urls.RECIPIENTS_URL.
225            recipient_groups_url (str, optional): The URL of the recipient groups endpoint. Defaults to urls.RECIPIENT_GROUPS_URL.
226            completed_lessons_url (str, optional): The URL of the completed lessons endpoint. Defaults to urls.COMPLETED_LESSONS_URL.
227            gateway_api_attendance (str, optional): The URL of the gateway API attendance endpoint. Defaults to urls.GATEWAY_API_ATTENDANCE.
228            refresh_oauth_url (str, optional): The URL of the refresh OAuth endpoint. Defaults to urls.REFRESH_OAUTH_URL.
229            proxy (Dict[str, str], optional): A dictionary containing proxy settings. Defaults to an empty dictionary.
230         """
231
232    def get_token(
233        self,
234        username: str,
235        password: str,
236    ) -> Token:
237        """
238        Retrieves an authentication Token class for the provided username and password.
239
240        Args:
241            username (str): The username for authentication.
242            password (str): The password for authentication.
243
244        Returns:
245            Token: An authentication token containing 'DZIENNIKSID' and 'SDZIENNIKSID' cookies.
246
247        Raises:
248            MaintananceError: If the API returns a maintenance status code or message.
249            AuthorizationError: If there is an error during the authorization process.
250        """
251        with self._session as s:
252            s.headers = urls.HEADERS
253            maint_check = s.get(self.API_URL, proxies=self.proxy)
254            if maint_check.status_code == 503:
255                message_list = maint_check.json().get("Message")
256                if not message_list:
257                    # during recent maintenance there were no messages (empty list)
258                    raise MaintananceError("maintenance")
259                raise MaintananceError(message_list[0]["description"])
260            s.get(
261                self.API_URL
262                + "/OAuth/Authorization?client_id=46&response_type=code&scope=mydata",
263                proxies=self.proxy,
264            )
265            response = s.post(
266                self.API_URL + "/OAuth/Authorization?client_id=46",
267                data={"action": "login", "login": username, "pass": password},
268                proxies=self.proxy,
269            )
270            if response.json()["status"] == "error":
271                raise AuthorizationError(response.json()["errors"][0]["message"])
272
273            s.get(self.API_URL + response.json().get("goTo"), proxies=self.proxy)
274
275            cookies: Dict = dict_from_cookiejar(s.cookies)
276            dzienniks = cookies.get("DZIENNIKSID")
277            sdzienniks = cookies.get("SDZIENNIKSID")
278            if dzienniks is None or sdzienniks is None:
279                raise AuthorizationError("Authorization cookies were not found")
280
281            token = Token(dzienniks=dzienniks, sdzienniks=sdzienniks)
282            self.token = token
283            return token
284
285    def refresh_oauth(self) -> str:
286        """
287        Refreshes the OAuth token.
288
289        Returns:
290            str: The new OAuth token.
291
292        Raises:
293            AuthorizationError: If the token cannot be refreshed.
294        """
295        self.cookies.update(self.token.access_cookies())
296        with self._session as s:
297            s.headers = urls.HEADERS
298            s.cookies = self.cookies
299            response: Response = s.get(self.REFRESH_URL, proxies=self.proxy)
300            if response.status_code == 200:
301                oauth = response.cookies.get("oauth_token")
302                self.token.oauth = oauth
303                return oauth
304        raise AuthorizationError(
305            f"Error while refreshing oauth token {response.content}"
306        )
307
308    def post(self, url: str, data: Dict[str, str]) -> Response:
309        """
310        Makes a POST request to the specified URL with the given data.
311
312        Args:
313            url (str): The URL to send the POST request to.
314            data (Dict[str, Union[str, int]]): The data to include in the POST request.
315
316        Returns:
317            Response: The response from the server.
318        """
319        self.cookies.update(self.token.access_cookies())
320        with self._session as s:
321            s.headers = urls.HEADERS
322            s.cookies = self.cookies
323            response: Response = s.post(url, data=data, proxies=self.proxy)
324            return response
325
326    def get(self, url: str) -> Response:
327        """
328        Makes a GET request to the specified URL.
329
330        Args:
331            url (str): The URL to send the GET request to.
332
333        Returns:
334            Response: The response from the server.
335        """
336        self.cookies.update(self.token.access_cookies())
337        with self._session as s:
338            s.headers = urls.HEADERS
339            s.cookies = self.cookies
340            response: Response = s.get(url, proxies=self.proxy)
341            return response
342
343
344def new_client(
345    token: Token = Token(),
346    base_url: str = urls.BASE_URL,
347    api_url: str = urls.API_URL,
348    grades_url: str = urls.GRADES_URL,
349    timetable_url: str = urls.TIMETABLE_URL,
350    announcements_url: str = urls.ANNOUNCEMENTS_URL,
351    message_url: str = urls.MESSAGE_URL,
352    send_message_url: str = urls.SEND_MESSAGE_URL,
353    attendance_url: str = urls.ATTENDANCE_URL,
354    attendance_details_url: str = urls.ATTENDANCE_DETAILS_URL,
355    schedule_url: str = urls.SCHEDULE_URL,
356    recent_schedule_url: str = urls.RECENT_SCHEDULE_URL,
357    homework_url: str = urls.HOMEWORK_URL,
358    homework_details_url: str = urls.HOMEWORK_DETAILS_URL,
359    info_url: str = urls.INFO_URL,
360    recipients_url: str = urls.RECIPIENTS_URL,
361    recipient_groups_url: str = urls.RECIPIENT_GROUPS_URL,
362    completed_lessons_url: str = urls.COMPLETED_LESSONS_URL,
363    gateway_api_attendance: str = urls.GATEWAY_API_ATTENDANCE,
364    refresh_oauth_url: str = urls.REFRESH_OAUTH_URL,
365    index_url: str = urls.INDEX_URL,
366    proxy: dict[str, str] = {},
367):
368    """
369    Creates a new instance of the Client class.
370
371    Args:
372        token (Optional[Token], optional): The authentication token. Defaults to None.
373        base_url (str, optional): The base URL of the API. Defaults to urls.BASE_URL.
374        api_url (str, optional): The URL of the API endpoint. Defaults to urls.API_URL.
375        grades_url (str, optional): The URL of the grades endpoint. Defaults to urls.GRADES_URL.
376        timetable_url (str, optional): The URL of the timetable endpoint. Defaults to urls.TIMETABLE_URL.
377        announcements_url (str, optional): The URL of the announcements endpoint. Defaults to urls.ANNOUNCEMENTS_URL.
378        message_url (str, optional): The URL of the message endpoint. Defaults to urls.MESSAGE_URL.
379        send_message_url (str, optional): The URL of the send message endpoint. Defaults to urls.SEND_MESSAGE_URL.
380        attendance_url (str, optional): The URL of the attendance endpoint. Defaults to urls.ATTENDANCE_URL.
381        attendance_details_url (str, optional): The URL of the attendance details endpoint. Defaults to urls.ATTENDANCE_DETAILS_URL.
382        schedule_url (str, optional): The URL of the schedule endpoint. Defaults to urls.SCHEDULE_URL.
383        homework_url (str, optional): The URL of the homework endpoint. Defaults to urls.HOMEWORK_URL.
384        homework_details_url (str, optional): The URL of the homework details endpoint. Defaults to urls.HOMEWORK_DETAILS_URL.
385        info_url (str, optional): The URL of the info endpoint. Defaults to urls.INFO_URL.
386        recipients_url (str, optional): The URL of the recipients endpoint. Defaults to urls.RECIPIENTS_URL.
387        recipient_groups_url (str, optional): The URL of the recipient groups endpoint. Defaults to urls.RECIPIENT_GROUPS_URL.
388        completed_lessons_url (str, optional): The URL of the completed lessons endpoint. Defaults to urls.COMPLETED_LESSONS_URL.
389        gateway_api_attendance (str, optional): The URL of the gateway API attendance endpoint. Defaults to urls.GATEWAY_API_ATTENDANCE.
390        refresh_oauth_url (str, optional): The URL of the refresh OAuth endpoint. Defaults to urls.REFRESH_OAUTH_URL.
391        index_url (str, optional): The url for student index
392        proxy (dict[str, str], optional): A dictionary containing proxy settings. Defaults to an empty dictionary.
393
394    Returns:
395        Client: A new instance of the Client class.
396    """
397    if not isinstance(token, Token):
398        token = Token()
399    return Client(
400        token,
401        base_url,
402        api_url,
403        grades_url,
404        timetable_url,
405        announcements_url,
406        message_url,
407        send_message_url,
408        attendance_url,
409        attendance_details_url,
410        schedule_url,
411        recent_schedule_url,
412        homework_url,
413        homework_details_url,
414        info_url,
415        recipients_url,
416        recipient_groups_url,
417        completed_lessons_url,
418        gateway_api_attendance,
419        refresh_oauth_url,
420        index_url,
421        proxy,
422    )
class Token:
 36class Token:
 37    """
 38     A class to manage and store API tokens.
 39
 40    The API key should be formatted as "{DZIENNIKSID}:{SDZIENNIKSID}".
 41
 42    Attributes:
 43        API_Key (str): The combined API key.
 44        csrf_token (str): CSRF token for the session.
 45        oauth (str): OAuth token for the session.
 46
 47    Methods:
 48        _parse_api_key(API_Key: str) -> dict:
 49            Parses the API key and returns a dictionary with the tokens used for cookies.
 50        Raises:
 51            TokenKeyError: If the API_Key is not in the correct format.
 52    """
 53
 54    def __init__(
 55        self,
 56        API_Key: Optional[str] = None,
 57        dzienniks: Optional[str] = None,
 58        sdzienniks: Optional[str] = None,
 59    ):
 60        """
 61        Initializes the Token object with the given API key or token parts.
 62
 63        Args:
 64            API_Key (str, optional): The API key in the format 'DZIENNIKSID:SDZIENNIKSID'. Defaults to None.
 65            dzienniks (str, optional): The first part of the API key. Defaults to None / Ignored if API_Key is passed.
 66            sdzienniks (str, optional): The second part of the API key. Defaults to None / Ignored if API_Key is passed.
 67        """
 68        if API_Key:
 69            key = API_Key
 70        elif dzienniks and sdzienniks:
 71            key = f"{dzienniks}:{sdzienniks}"
 72        else:
 73            key = ""
 74
 75        self.API_Key = key
 76        self.csrf_token = ""
 77        self.oauth = ""
 78
 79    def __repr__(self) -> str:
 80        """
 81        Returns a string representation of the API Key.
 82
 83        Returns:
 84            str: A string representation of the API Key.
 85        """
 86        return self.API_Key
 87
 88    def _parse_api_key(self, API_Key: str) -> dict:
 89        """
 90        Parses the API Key string into a dictionary.
 91
 92        The API Key string should be in the format 'DZIENNIKSID:SDZIENNIKSID'.
 93
 94        Args:
 95            API_Key (str): The API Key string to be parsed.
 96
 97        Returns:
 98            dict: A dictionary containing the parsed API Key, with keys 'DZIENNIKSID' and 'SDZIENNIKSID'.
 99
100        Raises:
101            TokenKeyError: If the API Key is not in the correct format.
102        """
103        parts = API_Key.split(":")
104        if len(parts) != 2:
105            raise TokenKeyError(
106                "API_Key must be in the format 'DZIENNIKSID:SDZIENNIKSID'"
107            )
108        return {"DZIENNIKSID": parts[0], "SDZIENNIKSID": parts[1]}
109
110    def access_cookies(self) -> RequestsCookieJar:
111        """
112        returns CookieJar containing authorization cookies.
113
114        Returns:
115            RequestsCookieJar: A CookieJar containing the authorization cookies generated from the parsed API Key.
116        """
117        return cookiejar_from_dict(self._parse_api_key(self.API_Key))

A class to manage and store API tokens.

The API key should be formatted as "{DZIENNIKSID}:{SDZIENNIKSID}".

Attributes: API_Key (str): The combined API key. csrf_token (str): CSRF token for the session. oauth (str): OAuth token for the session.

Methods: _parse_api_key(API_Key: str) -> dict: Parses the API key and returns a dictionary with the tokens used for cookies. Raises: TokenKeyError: If the API_Key is not in the correct format.

Token( API_Key: Optional[str] = None, dzienniks: Optional[str] = None, sdzienniks: Optional[str] = None)
54    def __init__(
55        self,
56        API_Key: Optional[str] = None,
57        dzienniks: Optional[str] = None,
58        sdzienniks: Optional[str] = None,
59    ):
60        """
61        Initializes the Token object with the given API key or token parts.
62
63        Args:
64            API_Key (str, optional): The API key in the format 'DZIENNIKSID:SDZIENNIKSID'. Defaults to None.
65            dzienniks (str, optional): The first part of the API key. Defaults to None / Ignored if API_Key is passed.
66            sdzienniks (str, optional): The second part of the API key. Defaults to None / Ignored if API_Key is passed.
67        """
68        if API_Key:
69            key = API_Key
70        elif dzienniks and sdzienniks:
71            key = f"{dzienniks}:{sdzienniks}"
72        else:
73            key = ""
74
75        self.API_Key = key
76        self.csrf_token = ""
77        self.oauth = ""

Initializes the Token object with the given API key or token parts.

Args: API_Key (str, optional): The API key in the format 'DZIENNIKSID:SDZIENNIKSID'. Defaults to None. dzienniks (str, optional): The first part of the API key. Defaults to None / Ignored if API_Key is passed. sdzienniks (str, optional): The second part of the API key. Defaults to None / Ignored if API_Key is passed.

API_Key
csrf_token
oauth
def access_cookies(self) -> requests.cookies.RequestsCookieJar:
110    def access_cookies(self) -> RequestsCookieJar:
111        """
112        returns CookieJar containing authorization cookies.
113
114        Returns:
115            RequestsCookieJar: A CookieJar containing the authorization cookies generated from the parsed API Key.
116        """
117        return cookiejar_from_dict(self._parse_api_key(self.API_Key))

returns CookieJar containing authorization cookies.

Returns: RequestsCookieJar: A CookieJar containing the authorization cookies generated from the parsed API Key.

class Client:
120class Client:
121    """
122    A class to handle HTTP operations using the tokens.
123
124    Attributes:
125        token (Token): The Token object containing the API key and tokens.
126        proxy (dict): The proxy settings for the session.
127        BASE_URL (str): The base URL for the site.
128        API_URL (str): The API URL.
129        GRADES_URL (str): The URL for grades.
130        TIMETABLE_URL (str): The URL for the timetable.
131        ANNOUNCEMENTS_URL (str): The URL for announcements.
132        MESSAGE_URL (str): The URL for messages.
133        SEND_MESSAGE_URL (str): The URL for sending messages.
134        ATTENDANCE_URL (str): The URL for attendance.
135        ATTENDANCE_DETAILS_URL (str): The URL for attendance details.
136        SCHEDULE_URL (str): The URL for the schedule.
137        HOMEWORK_URL (str): The URL for homework.
138        HOMEWORK_DETAILS_URL (str): The URL for homework details.
139        INFO_URL (str): The URL for information.
140        COMPLETED_LESSONS_URL (str): The URL for completed lessons.
141        GATEWAY_API_ATTENDANCE (str): The URL for gateway API attendance.
142        RECIPIENTS_URL (str): The URL for recipients.
143        RECIPIENT_GROUPS_URL (str): The URL for recipient groups.
144        INDEX_URL (str): Url for student index
145        cookies (RequestsCookieJar): additional cookies
146        _session (Session): The requests session for making HTTP calls.
147
148    Methods:
149        refresh_oauth() -> str:
150            Refreshes the OAuth token then returns it.
151        post(url: str, data: Dict[str, str]) -> Response:
152            Makes a POST request to the specified URL with the given data.
153        get(url: str) -> Response:
154            Makes a GET request to the specified URL.
155    """
156
157    def __init__(
158        self,
159        token: Token,
160        base_url: str = urls.BASE_URL,
161        api_url: str = urls.API_URL,
162        grades_url: str = urls.GRADES_URL,
163        timetable_url: str = urls.TIMETABLE_URL,
164        announcements_url: str = urls.ANNOUNCEMENTS_URL,
165        message_url: str = urls.MESSAGE_URL,
166        send_message_url: str = urls.SEND_MESSAGE_URL,
167        attendance_url: str = urls.ATTENDANCE_URL,
168        attendance_details_url: str = urls.ATTENDANCE_DETAILS_URL,
169        schedule_url: str = urls.SCHEDULE_URL,
170        recent_schedule_url: str = urls.RECENT_SCHEDULE_URL,
171        homework_url: str = urls.HOMEWORK_URL,
172        homework_details_url: str = urls.HOMEWORK_DETAILS_URL,
173        info_url: str = urls.INFO_URL,
174        recipients_url: str = urls.RECIPIENTS_URL,
175        recipient_groups_url: str = urls.RECIPIENT_GROUPS_URL,
176        completed_lessons_url: str = urls.COMPLETED_LESSONS_URL,
177        gateway_api_attendance: str = urls.GATEWAY_API_ATTENDANCE,
178        refresh_oauth_url: str = urls.REFRESH_OAUTH_URL,
179        index_url: str = urls.INDEX_URL,
180        proxy: Dict[str, str] = {},
181        extra_cookies: RequestsCookieJar = RequestsCookieJar(),
182    ):
183        self.token = token
184        self.proxy = proxy
185        self.BASE_URL = base_url
186        self.API_URL = api_url
187        self.GRADES_URL = grades_url
188        self.TIMETABLE_URL = timetable_url
189        self.ANNOUNCEMENTS_URL = announcements_url
190        self.MESSAGE_URL = message_url
191        self.SEND_MESSAGE_URL = send_message_url
192        self.ATTENDANCE_URL = attendance_url
193        self.ATTENDANCE_DETAILS_URL = attendance_details_url
194        self.SCHEDULE_URL = schedule_url
195        self.RECENT_SCHEDULE_URL = recent_schedule_url
196        self.HOMEWORK_URL = homework_url
197        self.HOMEWORK_DETAILS_URL = homework_details_url
198        self.INFO_URL = info_url
199        self.COMPLETED_LESSONS_URL = completed_lessons_url
200        self.GATEWAY_API_ATTENDANCE = gateway_api_attendance
201        self.RECIPIENTS_URL = recipients_url
202        self.RECIPIENT_GROUPS_URL = recipient_groups_url
203        self.REFRESH_URL = refresh_oauth_url
204        self.INDEX_URL = index_url
205        self.cookies = extra_cookies
206        self._session = Session()
207        """
208        Initializes a new instance of Client.
209
210        Args:
211            token (Token): The authentication token required for API access.
212            base_url (str, optional): The base URL of the API. Defaults to urls.BASE_URL.
213            api_url (str, optional): The URL of the API endpoint. Defaults to urls.API_URL.
214            grades_url (str, optional): The URL of the grades endpoint. Defaults to urls.GRADES_URL.
215            timetable_url (str, optional): The URL of the timetable endpoint. Defaults to urls.TIMETABLE_URL.
216            announcements_url (str, optional): The URL of the announcements endpoint. Defaults to urls.ANNOUNCEMENTS_URL.
217            message_url (str, optional): The URL of the message endpoint. Defaults to urls.MESSAGE_URL.
218            send_message_url (str, optional): The URL of the send message endpoint. Defaults to urls.SEND_MESSAGE_URL.
219            attendance_url (str, optional): The URL of the attendance endpoint. Defaults to urls.ATTENDANCE_URL.
220            attendance_details_url (str, optional): The URL of the attendance details endpoint. Defaults to urls.ATTENDANCE_DETAILS_URL.
221            schedule_url (str, optional): The URL of the schedule endpoint. Defaults to urls.SCHEDULE_URL.
222            homework_url (str, optional): The URL of the homework endpoint. Defaults to urls.HOMEWORK_URL.
223            homework_details_url (str, optional): The URL of the homework details endpoint. Defaults to urls.HOMEWORK_DETAILS_URL.
224            info_url (str, optional): The URL of the info endpoint. Defaults to urls.INFO_URL.
225            recipients_url (str, optional): The URL of the recipients endpoint. Defaults to urls.RECIPIENTS_URL.
226            recipient_groups_url (str, optional): The URL of the recipient groups endpoint. Defaults to urls.RECIPIENT_GROUPS_URL.
227            completed_lessons_url (str, optional): The URL of the completed lessons endpoint. Defaults to urls.COMPLETED_LESSONS_URL.
228            gateway_api_attendance (str, optional): The URL of the gateway API attendance endpoint. Defaults to urls.GATEWAY_API_ATTENDANCE.
229            refresh_oauth_url (str, optional): The URL of the refresh OAuth endpoint. Defaults to urls.REFRESH_OAUTH_URL.
230            proxy (Dict[str, str], optional): A dictionary containing proxy settings. Defaults to an empty dictionary.
231         """
232
233    def get_token(
234        self,
235        username: str,
236        password: str,
237    ) -> Token:
238        """
239        Retrieves an authentication Token class for the provided username and password.
240
241        Args:
242            username (str): The username for authentication.
243            password (str): The password for authentication.
244
245        Returns:
246            Token: An authentication token containing 'DZIENNIKSID' and 'SDZIENNIKSID' cookies.
247
248        Raises:
249            MaintananceError: If the API returns a maintenance status code or message.
250            AuthorizationError: If there is an error during the authorization process.
251        """
252        with self._session as s:
253            s.headers = urls.HEADERS
254            maint_check = s.get(self.API_URL, proxies=self.proxy)
255            if maint_check.status_code == 503:
256                message_list = maint_check.json().get("Message")
257                if not message_list:
258                    # during recent maintenance there were no messages (empty list)
259                    raise MaintananceError("maintenance")
260                raise MaintananceError(message_list[0]["description"])
261            s.get(
262                self.API_URL
263                + "/OAuth/Authorization?client_id=46&response_type=code&scope=mydata",
264                proxies=self.proxy,
265            )
266            response = s.post(
267                self.API_URL + "/OAuth/Authorization?client_id=46",
268                data={"action": "login", "login": username, "pass": password},
269                proxies=self.proxy,
270            )
271            if response.json()["status"] == "error":
272                raise AuthorizationError(response.json()["errors"][0]["message"])
273
274            s.get(self.API_URL + response.json().get("goTo"), proxies=self.proxy)
275
276            cookies: Dict = dict_from_cookiejar(s.cookies)
277            dzienniks = cookies.get("DZIENNIKSID")
278            sdzienniks = cookies.get("SDZIENNIKSID")
279            if dzienniks is None or sdzienniks is None:
280                raise AuthorizationError("Authorization cookies were not found")
281
282            token = Token(dzienniks=dzienniks, sdzienniks=sdzienniks)
283            self.token = token
284            return token
285
286    def refresh_oauth(self) -> str:
287        """
288        Refreshes the OAuth token.
289
290        Returns:
291            str: The new OAuth token.
292
293        Raises:
294            AuthorizationError: If the token cannot be refreshed.
295        """
296        self.cookies.update(self.token.access_cookies())
297        with self._session as s:
298            s.headers = urls.HEADERS
299            s.cookies = self.cookies
300            response: Response = s.get(self.REFRESH_URL, proxies=self.proxy)
301            if response.status_code == 200:
302                oauth = response.cookies.get("oauth_token")
303                self.token.oauth = oauth
304                return oauth
305        raise AuthorizationError(
306            f"Error while refreshing oauth token {response.content}"
307        )
308
309    def post(self, url: str, data: Dict[str, str]) -> Response:
310        """
311        Makes a POST request to the specified URL with the given data.
312
313        Args:
314            url (str): The URL to send the POST request to.
315            data (Dict[str, Union[str, int]]): The data to include in the POST request.
316
317        Returns:
318            Response: The response from the server.
319        """
320        self.cookies.update(self.token.access_cookies())
321        with self._session as s:
322            s.headers = urls.HEADERS
323            s.cookies = self.cookies
324            response: Response = s.post(url, data=data, proxies=self.proxy)
325            return response
326
327    def get(self, url: str) -> Response:
328        """
329        Makes a GET request to the specified URL.
330
331        Args:
332            url (str): The URL to send the GET request to.
333
334        Returns:
335            Response: The response from the server.
336        """
337        self.cookies.update(self.token.access_cookies())
338        with self._session as s:
339            s.headers = urls.HEADERS
340            s.cookies = self.cookies
341            response: Response = s.get(url, proxies=self.proxy)
342            return response

A class to handle HTTP operations using the tokens.

Attributes: token (Token): The Token object containing the API key and tokens. proxy (dict): The proxy settings for the session. BASE_URL (str): The base URL for the site. API_URL (str): The API URL. GRADES_URL (str): The URL for grades. TIMETABLE_URL (str): The URL for the timetable. ANNOUNCEMENTS_URL (str): The URL for announcements. MESSAGE_URL (str): The URL for messages. SEND_MESSAGE_URL (str): The URL for sending messages. ATTENDANCE_URL (str): The URL for attendance. ATTENDANCE_DETAILS_URL (str): The URL for attendance details. SCHEDULE_URL (str): The URL for the schedule. HOMEWORK_URL (str): The URL for homework. HOMEWORK_DETAILS_URL (str): The URL for homework details. INFO_URL (str): The URL for information. COMPLETED_LESSONS_URL (str): The URL for completed lessons. GATEWAY_API_ATTENDANCE (str): The URL for gateway API attendance. RECIPIENTS_URL (str): The URL for recipients. RECIPIENT_GROUPS_URL (str): The URL for recipient groups. INDEX_URL (str): Url for student index cookies (RequestsCookieJar): additional cookies _session (Session): The requests session for making HTTP calls.

Methods: refresh_oauth() -> str: Refreshes the OAuth token then returns it. post(url: str, data: Dict[str, str]) -> Response: Makes a POST request to the specified URL with the given data. get(url: str) -> Response: Makes a GET request to the specified URL.

Client( token: Token, base_url: str = 'https://synergia.librus.pl', api_url: str = 'https://api.librus.pl', grades_url: str = 'https://synergia.librus.pl/przegladaj_oceny/uczen', timetable_url: str = 'https://synergia.librus.pl/przegladaj_plan_lekcji', announcements_url: str = 'https://synergia.librus.pl/ogloszenia', message_url: str = 'https://synergia.librus.pl/wiadomosci/1/5', send_message_url: str = 'https://synergia.librus.pl/wiadomosci/1/6', attendance_url: str = 'https://synergia.librus.pl/przegladaj_nb/uczen', attendance_details_url: str = 'https://synergia.librus.pl/przegladaj_nb/szczegoly/', schedule_url: str = 'https://synergia.librus.pl/terminarz/', recent_schedule_url: str = 'https://synergia.librus.pl/terminarz/dodane_od_ostatniego_logowania', homework_url: str = 'https://synergia.librus.pl/moje_zadania', homework_details_url: str = 'https://synergia.librus.pl/moje_zadania/podglad/', info_url: str = 'https://synergia.librus.pl/informacja', recipients_url: str = 'https://synergia.librus.pl/getRecipients', recipient_groups_url: str = 'https://synergia.librus.pl/wiadomosci/2/6', completed_lessons_url: str = 'https://synergia.librus.pl/zrealizowane_lekcje', gateway_api_attendance: str = 'https://synergia.librus.pl/gateway/api/2.0/Attendances', refresh_oauth_url: str = 'https://synergia.librus.pl/refreshToken', index_url: str = 'https://synergia.librus.pl/uczen/index', proxy: Dict[str, str] = {}, extra_cookies: requests.cookies.RequestsCookieJar = <RequestsCookieJar[]>)
157    def __init__(
158        self,
159        token: Token,
160        base_url: str = urls.BASE_URL,
161        api_url: str = urls.API_URL,
162        grades_url: str = urls.GRADES_URL,
163        timetable_url: str = urls.TIMETABLE_URL,
164        announcements_url: str = urls.ANNOUNCEMENTS_URL,
165        message_url: str = urls.MESSAGE_URL,
166        send_message_url: str = urls.SEND_MESSAGE_URL,
167        attendance_url: str = urls.ATTENDANCE_URL,
168        attendance_details_url: str = urls.ATTENDANCE_DETAILS_URL,
169        schedule_url: str = urls.SCHEDULE_URL,
170        recent_schedule_url: str = urls.RECENT_SCHEDULE_URL,
171        homework_url: str = urls.HOMEWORK_URL,
172        homework_details_url: str = urls.HOMEWORK_DETAILS_URL,
173        info_url: str = urls.INFO_URL,
174        recipients_url: str = urls.RECIPIENTS_URL,
175        recipient_groups_url: str = urls.RECIPIENT_GROUPS_URL,
176        completed_lessons_url: str = urls.COMPLETED_LESSONS_URL,
177        gateway_api_attendance: str = urls.GATEWAY_API_ATTENDANCE,
178        refresh_oauth_url: str = urls.REFRESH_OAUTH_URL,
179        index_url: str = urls.INDEX_URL,
180        proxy: Dict[str, str] = {},
181        extra_cookies: RequestsCookieJar = RequestsCookieJar(),
182    ):
183        self.token = token
184        self.proxy = proxy
185        self.BASE_URL = base_url
186        self.API_URL = api_url
187        self.GRADES_URL = grades_url
188        self.TIMETABLE_URL = timetable_url
189        self.ANNOUNCEMENTS_URL = announcements_url
190        self.MESSAGE_URL = message_url
191        self.SEND_MESSAGE_URL = send_message_url
192        self.ATTENDANCE_URL = attendance_url
193        self.ATTENDANCE_DETAILS_URL = attendance_details_url
194        self.SCHEDULE_URL = schedule_url
195        self.RECENT_SCHEDULE_URL = recent_schedule_url
196        self.HOMEWORK_URL = homework_url
197        self.HOMEWORK_DETAILS_URL = homework_details_url
198        self.INFO_URL = info_url
199        self.COMPLETED_LESSONS_URL = completed_lessons_url
200        self.GATEWAY_API_ATTENDANCE = gateway_api_attendance
201        self.RECIPIENTS_URL = recipients_url
202        self.RECIPIENT_GROUPS_URL = recipient_groups_url
203        self.REFRESH_URL = refresh_oauth_url
204        self.INDEX_URL = index_url
205        self.cookies = extra_cookies
206        self._session = Session()
207        """
208        Initializes a new instance of Client.
209
210        Args:
211            token (Token): The authentication token required for API access.
212            base_url (str, optional): The base URL of the API. Defaults to urls.BASE_URL.
213            api_url (str, optional): The URL of the API endpoint. Defaults to urls.API_URL.
214            grades_url (str, optional): The URL of the grades endpoint. Defaults to urls.GRADES_URL.
215            timetable_url (str, optional): The URL of the timetable endpoint. Defaults to urls.TIMETABLE_URL.
216            announcements_url (str, optional): The URL of the announcements endpoint. Defaults to urls.ANNOUNCEMENTS_URL.
217            message_url (str, optional): The URL of the message endpoint. Defaults to urls.MESSAGE_URL.
218            send_message_url (str, optional): The URL of the send message endpoint. Defaults to urls.SEND_MESSAGE_URL.
219            attendance_url (str, optional): The URL of the attendance endpoint. Defaults to urls.ATTENDANCE_URL.
220            attendance_details_url (str, optional): The URL of the attendance details endpoint. Defaults to urls.ATTENDANCE_DETAILS_URL.
221            schedule_url (str, optional): The URL of the schedule endpoint. Defaults to urls.SCHEDULE_URL.
222            homework_url (str, optional): The URL of the homework endpoint. Defaults to urls.HOMEWORK_URL.
223            homework_details_url (str, optional): The URL of the homework details endpoint. Defaults to urls.HOMEWORK_DETAILS_URL.
224            info_url (str, optional): The URL of the info endpoint. Defaults to urls.INFO_URL.
225            recipients_url (str, optional): The URL of the recipients endpoint. Defaults to urls.RECIPIENTS_URL.
226            recipient_groups_url (str, optional): The URL of the recipient groups endpoint. Defaults to urls.RECIPIENT_GROUPS_URL.
227            completed_lessons_url (str, optional): The URL of the completed lessons endpoint. Defaults to urls.COMPLETED_LESSONS_URL.
228            gateway_api_attendance (str, optional): The URL of the gateway API attendance endpoint. Defaults to urls.GATEWAY_API_ATTENDANCE.
229            refresh_oauth_url (str, optional): The URL of the refresh OAuth endpoint. Defaults to urls.REFRESH_OAUTH_URL.
230            proxy (Dict[str, str], optional): A dictionary containing proxy settings. Defaults to an empty dictionary.
231         """
token
proxy
BASE_URL
API_URL
GRADES_URL
TIMETABLE_URL
ANNOUNCEMENTS_URL
MESSAGE_URL
SEND_MESSAGE_URL
ATTENDANCE_URL
ATTENDANCE_DETAILS_URL
SCHEDULE_URL
RECENT_SCHEDULE_URL
HOMEWORK_URL
HOMEWORK_DETAILS_URL
INFO_URL
COMPLETED_LESSONS_URL
GATEWAY_API_ATTENDANCE
RECIPIENTS_URL
RECIPIENT_GROUPS_URL
REFRESH_URL
INDEX_URL
cookies
def get_token(self, username: str, password: str) -> Token:
233    def get_token(
234        self,
235        username: str,
236        password: str,
237    ) -> Token:
238        """
239        Retrieves an authentication Token class for the provided username and password.
240
241        Args:
242            username (str): The username for authentication.
243            password (str): The password for authentication.
244
245        Returns:
246            Token: An authentication token containing 'DZIENNIKSID' and 'SDZIENNIKSID' cookies.
247
248        Raises:
249            MaintananceError: If the API returns a maintenance status code or message.
250            AuthorizationError: If there is an error during the authorization process.
251        """
252        with self._session as s:
253            s.headers = urls.HEADERS
254            maint_check = s.get(self.API_URL, proxies=self.proxy)
255            if maint_check.status_code == 503:
256                message_list = maint_check.json().get("Message")
257                if not message_list:
258                    # during recent maintenance there were no messages (empty list)
259                    raise MaintananceError("maintenance")
260                raise MaintananceError(message_list[0]["description"])
261            s.get(
262                self.API_URL
263                + "/OAuth/Authorization?client_id=46&response_type=code&scope=mydata",
264                proxies=self.proxy,
265            )
266            response = s.post(
267                self.API_URL + "/OAuth/Authorization?client_id=46",
268                data={"action": "login", "login": username, "pass": password},
269                proxies=self.proxy,
270            )
271            if response.json()["status"] == "error":
272                raise AuthorizationError(response.json()["errors"][0]["message"])
273
274            s.get(self.API_URL + response.json().get("goTo"), proxies=self.proxy)
275
276            cookies: Dict = dict_from_cookiejar(s.cookies)
277            dzienniks = cookies.get("DZIENNIKSID")
278            sdzienniks = cookies.get("SDZIENNIKSID")
279            if dzienniks is None or sdzienniks is None:
280                raise AuthorizationError("Authorization cookies were not found")
281
282            token = Token(dzienniks=dzienniks, sdzienniks=sdzienniks)
283            self.token = token
284            return token

Retrieves an authentication Token class for the provided username and password.

Args: username (str): The username for authentication. password (str): The password for authentication.

Returns: Token: An authentication token containing 'DZIENNIKSID' and 'SDZIENNIKSID' cookies.

Raises: MaintananceError: If the API returns a maintenance status code or message. AuthorizationError: If there is an error during the authorization process.

def refresh_oauth(self) -> str:
286    def refresh_oauth(self) -> str:
287        """
288        Refreshes the OAuth token.
289
290        Returns:
291            str: The new OAuth token.
292
293        Raises:
294            AuthorizationError: If the token cannot be refreshed.
295        """
296        self.cookies.update(self.token.access_cookies())
297        with self._session as s:
298            s.headers = urls.HEADERS
299            s.cookies = self.cookies
300            response: Response = s.get(self.REFRESH_URL, proxies=self.proxy)
301            if response.status_code == 200:
302                oauth = response.cookies.get("oauth_token")
303                self.token.oauth = oauth
304                return oauth
305        raise AuthorizationError(
306            f"Error while refreshing oauth token {response.content}"
307        )

Refreshes the OAuth token.

Returns: str: The new OAuth token.

Raises: AuthorizationError: If the token cannot be refreshed.

def post(self, url: str, data: Dict[str, str]) -> requests.models.Response:
309    def post(self, url: str, data: Dict[str, str]) -> Response:
310        """
311        Makes a POST request to the specified URL with the given data.
312
313        Args:
314            url (str): The URL to send the POST request to.
315            data (Dict[str, Union[str, int]]): The data to include in the POST request.
316
317        Returns:
318            Response: The response from the server.
319        """
320        self.cookies.update(self.token.access_cookies())
321        with self._session as s:
322            s.headers = urls.HEADERS
323            s.cookies = self.cookies
324            response: Response = s.post(url, data=data, proxies=self.proxy)
325            return response

Makes a POST request to the specified URL with the given data.

Args: url (str): The URL to send the POST request to. data (Dict[str, Union[str, int]]): The data to include in the POST request.

Returns: Response: The response from the server.

def get(self, url: str) -> requests.models.Response:
327    def get(self, url: str) -> Response:
328        """
329        Makes a GET request to the specified URL.
330
331        Args:
332            url (str): The URL to send the GET request to.
333
334        Returns:
335            Response: The response from the server.
336        """
337        self.cookies.update(self.token.access_cookies())
338        with self._session as s:
339            s.headers = urls.HEADERS
340            s.cookies = self.cookies
341            response: Response = s.get(url, proxies=self.proxy)
342            return response

Makes a GET request to the specified URL.

Args: url (str): The URL to send the GET request to.

Returns: Response: The response from the server.

def new_client( token: Token =, base_url: str = 'https://synergia.librus.pl', api_url: str = 'https://api.librus.pl', grades_url: str = 'https://synergia.librus.pl/przegladaj_oceny/uczen', timetable_url: str = 'https://synergia.librus.pl/przegladaj_plan_lekcji', announcements_url: str = 'https://synergia.librus.pl/ogloszenia', message_url: str = 'https://synergia.librus.pl/wiadomosci/1/5', send_message_url: str = 'https://synergia.librus.pl/wiadomosci/1/6', attendance_url: str = 'https://synergia.librus.pl/przegladaj_nb/uczen', attendance_details_url: str = 'https://synergia.librus.pl/przegladaj_nb/szczegoly/', schedule_url: str = 'https://synergia.librus.pl/terminarz/', recent_schedule_url: str = 'https://synergia.librus.pl/terminarz/dodane_od_ostatniego_logowania', homework_url: str = 'https://synergia.librus.pl/moje_zadania', homework_details_url: str = 'https://synergia.librus.pl/moje_zadania/podglad/', info_url: str = 'https://synergia.librus.pl/informacja', recipients_url: str = 'https://synergia.librus.pl/getRecipients', recipient_groups_url: str = 'https://synergia.librus.pl/wiadomosci/2/6', completed_lessons_url: str = 'https://synergia.librus.pl/zrealizowane_lekcje', gateway_api_attendance: str = 'https://synergia.librus.pl/gateway/api/2.0/Attendances', refresh_oauth_url: str = 'https://synergia.librus.pl/refreshToken', index_url: str = 'https://synergia.librus.pl/uczen/index', proxy: dict[str, str] = {}):
345def new_client(
346    token: Token = Token(),
347    base_url: str = urls.BASE_URL,
348    api_url: str = urls.API_URL,
349    grades_url: str = urls.GRADES_URL,
350    timetable_url: str = urls.TIMETABLE_URL,
351    announcements_url: str = urls.ANNOUNCEMENTS_URL,
352    message_url: str = urls.MESSAGE_URL,
353    send_message_url: str = urls.SEND_MESSAGE_URL,
354    attendance_url: str = urls.ATTENDANCE_URL,
355    attendance_details_url: str = urls.ATTENDANCE_DETAILS_URL,
356    schedule_url: str = urls.SCHEDULE_URL,
357    recent_schedule_url: str = urls.RECENT_SCHEDULE_URL,
358    homework_url: str = urls.HOMEWORK_URL,
359    homework_details_url: str = urls.HOMEWORK_DETAILS_URL,
360    info_url: str = urls.INFO_URL,
361    recipients_url: str = urls.RECIPIENTS_URL,
362    recipient_groups_url: str = urls.RECIPIENT_GROUPS_URL,
363    completed_lessons_url: str = urls.COMPLETED_LESSONS_URL,
364    gateway_api_attendance: str = urls.GATEWAY_API_ATTENDANCE,
365    refresh_oauth_url: str = urls.REFRESH_OAUTH_URL,
366    index_url: str = urls.INDEX_URL,
367    proxy: dict[str, str] = {},
368):
369    """
370    Creates a new instance of the Client class.
371
372    Args:
373        token (Optional[Token], optional): The authentication token. Defaults to None.
374        base_url (str, optional): The base URL of the API. Defaults to urls.BASE_URL.
375        api_url (str, optional): The URL of the API endpoint. Defaults to urls.API_URL.
376        grades_url (str, optional): The URL of the grades endpoint. Defaults to urls.GRADES_URL.
377        timetable_url (str, optional): The URL of the timetable endpoint. Defaults to urls.TIMETABLE_URL.
378        announcements_url (str, optional): The URL of the announcements endpoint. Defaults to urls.ANNOUNCEMENTS_URL.
379        message_url (str, optional): The URL of the message endpoint. Defaults to urls.MESSAGE_URL.
380        send_message_url (str, optional): The URL of the send message endpoint. Defaults to urls.SEND_MESSAGE_URL.
381        attendance_url (str, optional): The URL of the attendance endpoint. Defaults to urls.ATTENDANCE_URL.
382        attendance_details_url (str, optional): The URL of the attendance details endpoint. Defaults to urls.ATTENDANCE_DETAILS_URL.
383        schedule_url (str, optional): The URL of the schedule endpoint. Defaults to urls.SCHEDULE_URL.
384        homework_url (str, optional): The URL of the homework endpoint. Defaults to urls.HOMEWORK_URL.
385        homework_details_url (str, optional): The URL of the homework details endpoint. Defaults to urls.HOMEWORK_DETAILS_URL.
386        info_url (str, optional): The URL of the info endpoint. Defaults to urls.INFO_URL.
387        recipients_url (str, optional): The URL of the recipients endpoint. Defaults to urls.RECIPIENTS_URL.
388        recipient_groups_url (str, optional): The URL of the recipient groups endpoint. Defaults to urls.RECIPIENT_GROUPS_URL.
389        completed_lessons_url (str, optional): The URL of the completed lessons endpoint. Defaults to urls.COMPLETED_LESSONS_URL.
390        gateway_api_attendance (str, optional): The URL of the gateway API attendance endpoint. Defaults to urls.GATEWAY_API_ATTENDANCE.
391        refresh_oauth_url (str, optional): The URL of the refresh OAuth endpoint. Defaults to urls.REFRESH_OAUTH_URL.
392        index_url (str, optional): The url for student index
393        proxy (dict[str, str], optional): A dictionary containing proxy settings. Defaults to an empty dictionary.
394
395    Returns:
396        Client: A new instance of the Client class.
397    """
398    if not isinstance(token, Token):
399        token = Token()
400    return Client(
401        token,
402        base_url,
403        api_url,
404        grades_url,
405        timetable_url,
406        announcements_url,
407        message_url,
408        send_message_url,
409        attendance_url,
410        attendance_details_url,
411        schedule_url,
412        recent_schedule_url,
413        homework_url,
414        homework_details_url,
415        info_url,
416        recipients_url,
417        recipient_groups_url,
418        completed_lessons_url,
419        gateway_api_attendance,
420        refresh_oauth_url,
421        index_url,
422        proxy,
423    )

Creates a new instance of the Client class.

Args: token (Optional[Token], optional): The authentication token. Defaults to None. base_url (str, optional): The base URL of the API. Defaults to urls.BASE_URL. api_url (str, optional): The URL of the API endpoint. Defaults to urls.API_URL. grades_url (str, optional): The URL of the grades endpoint. Defaults to urls.GRADES_URL. timetable_url (str, optional): The URL of the timetable endpoint. Defaults to urls.TIMETABLE_URL. announcements_url (str, optional): The URL of the announcements endpoint. Defaults to urls.ANNOUNCEMENTS_URL. message_url (str, optional): The URL of the message endpoint. Defaults to urls.MESSAGE_URL. send_message_url (str, optional): The URL of the send message endpoint. Defaults to urls.SEND_MESSAGE_URL. attendance_url (str, optional): The URL of the attendance endpoint. Defaults to urls.ATTENDANCE_URL. attendance_details_url (str, optional): The URL of the attendance details endpoint. Defaults to urls.ATTENDANCE_DETAILS_URL. schedule_url (str, optional): The URL of the schedule endpoint. Defaults to urls.SCHEDULE_URL. homework_url (str, optional): The URL of the homework endpoint. Defaults to urls.HOMEWORK_URL. homework_details_url (str, optional): The URL of the homework details endpoint. Defaults to urls.HOMEWORK_DETAILS_URL. info_url (str, optional): The URL of the info endpoint. Defaults to urls.INFO_URL. recipients_url (str, optional): The URL of the recipients endpoint. Defaults to urls.RECIPIENTS_URL. recipient_groups_url (str, optional): The URL of the recipient groups endpoint. Defaults to urls.RECIPIENT_GROUPS_URL. completed_lessons_url (str, optional): The URL of the completed lessons endpoint. Defaults to urls.COMPLETED_LESSONS_URL. gateway_api_attendance (str, optional): The URL of the gateway API attendance endpoint. Defaults to urls.GATEWAY_API_ATTENDANCE. refresh_oauth_url (str, optional): The URL of the refresh OAuth endpoint. Defaults to urls.REFRESH_OAUTH_URL. index_url (str, optional): The url for student index proxy (dict[str, str], optional): A dictionary containing proxy settings. Defaults to an empty dictionary.

Returns: Client: A new instance of the Client class.