|
1 | 1 | """Main kos_loader module""" |
2 | 2 |
|
3 | 3 | import asyncio |
| 4 | +import base64 |
4 | 5 | import dataclasses |
5 | 6 | import datetime |
6 | 7 | import itertools |
@@ -56,8 +57,6 @@ def get_output_file_path() -> pathlib.Path: |
56 | 57 |
|
57 | 58 | def decrypt_string(key: RSAPrivateKey, ciphertext_b64: str) -> str: |
58 | 59 | """Decrypt base64 encoded ciphertext with the given private key""" |
59 | | - import base64 |
60 | | - |
61 | 60 | ciphertext = base64.b64decode(ciphertext_b64) |
62 | 61 | plaintext = key.decrypt( |
63 | 62 | ciphertext, |
@@ -146,19 +145,19 @@ async def kos_session(user: Cookies) -> aiohttp.ClientSession: |
146 | 145 | logger.info("Testing KOS session") |
147 | 146 |
|
148 | 147 | # Try to access user info endpoint to verify if the cookies are valid |
149 | | - ATTEMPTS = 5 |
150 | | - for attempt in range(ATTEMPTS): |
| 148 | + max_attempts = 5 |
| 149 | + for attempt in range(max_attempts): |
151 | 150 | try: |
152 | 151 | async with session.get(f"{KOS_API}/me") as resp: |
153 | 152 | response = await resp.json() |
154 | 153 | assert "person" in response |
155 | 154 | assert "id" in response["person"] and isinstance(response["person"]["id"], int) |
156 | 155 | assert "username" in response["person"] and isinstance(response["person"]["username"], str) |
157 | | - logger.info("KOS session is valid", response) |
| 156 | + logger.info("KOS session is valid") |
158 | 157 | break |
159 | 158 | except (aiohttp.ClientResponseError, AssertionError) as ex: |
160 | 159 | logger.exception("KOS session is not valid - could not access user info", exc_info=ex) |
161 | | - if attempt < ATTEMPTS - 1: |
| 160 | + if attempt < max_attempts - 1: |
162 | 161 | logger.info("Retrying in 2 seconds...") |
163 | 162 | await asyncio.sleep(2) |
164 | 163 | else: |
|
0 commit comments