|
13 | 13 | from utils import GLOBAL_SSL_CONTEXT |
14 | 14 |
|
15 | 15 | if TYPE_CHECKING: |
16 | | - from collections.abc import Mapping, MutableMapping, Sequence |
| 16 | + from collections.abc import Mapping, Sequence |
17 | 17 | from http.cookies import Morsel |
18 | 18 | from logging import Logger |
19 | 19 | from typing import Final |
|
29 | 29 |
|
30 | 30 | logger: "Final[Logger]" = logging.getLogger("TeX-Bot") |
31 | 31 |
|
32 | | -SU_PLATFORM_ACCESS_COOKIE: "Final[str]" = settings["SU_PLATFORM_ACCESS_COOKIE"] |
33 | | - |
34 | | -BASE_SU_PLATFORM_WEB_HEADERS: "Final[Mapping[str, str]]" = { |
| 32 | +BASE_SU_PLATFORM_WEB_HEADERS: "Mapping[str, str]" = { |
35 | 33 | "Cache-Control": "no-cache", |
36 | 34 | "Pragma": "no-cache", |
37 | 35 | "Expires": "0", |
38 | 36 | } |
39 | 37 |
|
40 | | -BASE_SU_PLATFORM_WEB_COOKIES: "Final[MutableMapping[str, str]]" = { |
41 | | - ".AspNet.SharedCookie": SU_PLATFORM_ACCESS_COOKIE, |
| 38 | +BASE_SU_PLATFORM_WEB_COOKIES: "Mapping[str, str]" = { |
| 39 | + ".AspNet.SharedCookie": settings["SU_PLATFORM_ACCESS_COOKIE"], |
42 | 40 | } |
43 | 41 |
|
44 | 42 | MEMBERS_LIST_URL: "Final[str]" = f"https://guildofstudents.com/organisation/memberlist/{settings['ORGANISATION_ID']}/?sort=groups" |
|
48 | 46 |
|
49 | 47 | async def fetch_url_content_with_session(url: str) -> str: |
50 | 48 | """Fetch the HTTP content at the given URL, using a shared aiohttp session.""" |
| 49 | + global BASE_SU_PLATFORM_WEB_COOKIES # noqa: PLW0603 |
51 | 50 | async with ( |
52 | 51 | aiohttp.ClientSession( |
53 | 52 | headers=BASE_SU_PLATFORM_WEB_HEADERS, cookies=BASE_SU_PLATFORM_WEB_COOKIES |
54 | 53 | ) as http_session, |
55 | 54 | http_session.get(url=url, ssl=GLOBAL_SSL_CONTEXT) as http_response, |
56 | 55 | ): |
57 | | - returned_asp_cookie: Morsel | None = http_response.cookies.get(".AspNet.SharedCookie") # type: ignore[type-arg] |
| 56 | + returned_asp_cookie: Morsel[str] | None = http_response.cookies.get(".AspNet.SharedCookie") |
58 | 57 | if ( |
59 | | - returned_asp_cookie |
| 58 | + returned_asp_cookie is not None |
60 | 59 | and returned_asp_cookie.value |
61 | 60 | != BASE_SU_PLATFORM_WEB_COOKIES[".AspNet.SharedCookie"] |
62 | 61 | ): |
63 | 62 | logger.info("SU platform access cookie was updated by the server; updating local.") |
64 | | - BASE_SU_PLATFORM_WEB_COOKIES[".AspNet.SharedCookie"] = returned_asp_cookie.value |
| 63 | + BASE_SU_PLATFORM_WEB_COOKIES = { |
| 64 | + ".AspNet.SharedCookie": returned_asp_cookie.value, |
| 65 | + } |
65 | 66 | return await http_response.text() |
66 | 67 |
|
67 | 68 |
|
|
0 commit comments