From 80367987787982d81c490cb26f4bb533d8d25025 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:09:34 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 307d423e..fe0b7704 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: # - id: check-added-large-files - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black - repo: https://github.com/pre-commit/mirrors-prettier From 73c29d04a568301e50912993c2b8b07add0ccf4e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:09:50 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- classquiz/helpers/__init__.py | 24 ++++++++++++++---------- classquiz/helpers/pixabay.py | 7 ++++--- classquiz/kahoot_importer/get.py | 7 ++++--- classquiz/kahoot_importer/search.py | 9 ++++++--- classquiz/routers/eximport.py | 7 ++++--- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/classquiz/helpers/__init__.py b/classquiz/helpers/__init__.py index 0cdefc18..f4b0a1da 100644 --- a/classquiz/helpers/__init__.py +++ b/classquiz/helpers/__init__.py @@ -70,9 +70,10 @@ async def generate_spreadsheet(quiz_results: dict, quiz: Quiz, player_fields: di worksheet.write(i + 1, 1, question["time"]) try: - async with ClientSession() as session, session.get( - f"{settings.root_address}/api/v1/storage/download/{question['image']}" - ) as response: + async with ( + ClientSession() as session, + session.get(f"{settings.root_address}/api/v1/storage/download/{question['image']}") as response, + ): if "image" in response.headers.get("Content-Type"): img_data = BytesIO(await response.read()) worksheet.insert_image(i + 1, 2, question["image"], {"image_data": img_data}) @@ -226,13 +227,16 @@ async def telemetry_ping(): except ormar.exceptions.NoMatch: instance_data = InstanceData() await instance_data.save() - async with ClientSession() as session, session.post( - f"https://cit.mawoka.eu.org/public/{instance_data.instance_id}", - json={ - "public_quizzes": await Quiz.objects.filter(public=True).count(), - "private_quizzes": await Quiz.objects.filter(public=False).count(), - "users": await User.objects.count(), - }, + async with ( + ClientSession() as session, + session.post( + f"https://cit.mawoka.eu.org/public/{instance_data.instance_id}", + json={ + "public_quizzes": await Quiz.objects.filter(public=True).count(), + "private_quizzes": await Quiz.objects.filter(public=False).count(), + "users": await User.objects.count(), + }, + ), ): return diff --git a/classquiz/helpers/pixabay.py b/classquiz/helpers/pixabay.py index bcf07ae5..cbc193ed 100644 --- a/classquiz/helpers/pixabay.py +++ b/classquiz/helpers/pixabay.py @@ -125,9 +125,10 @@ class NotFoundError(Exception): async def get_images(api_key: str, params: GetImagesParams) -> GetImagesResponse: - async with ClientSession() as session, session.get( - "https://pixabay.com/api/", params={"key": api_key, **params.dict()} - ) as resp: + async with ( + ClientSession() as session, + session.get("https://pixabay.com/api/", params={"key": api_key, **params.dict()}) as resp, + ): if resp.status == 200: return GetImagesResponse.parse_obj(await resp.json()) else: diff --git a/classquiz/kahoot_importer/get.py b/classquiz/kahoot_importer/get.py index 4aa02dc1..96a18198 100644 --- a/classquiz/kahoot_importer/get.py +++ b/classquiz/kahoot_importer/get.py @@ -15,9 +15,10 @@ class _Response(BaseModel): async def get(game_id: str) -> _Response | int: - async with ClientSession() as session, session.get( - f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true" - ) as response: + async with ( + ClientSession() as session, + session.get(f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true") as response, + ): if response.status == 200: return _Response(**await response.json()) else: diff --git a/classquiz/kahoot_importer/search.py b/classquiz/kahoot_importer/search.py index 1f263d7c..201dac7e 100644 --- a/classquiz/kahoot_importer/search.py +++ b/classquiz/kahoot_importer/search.py @@ -35,7 +35,10 @@ async def search( :param limit: Less or equals 100 :return: """ - async with ClientSession() as session, session.get( - f"https://create.kahoot.it/rest/kahoots/?query={query}&limit={limit}&cursor={cursor}&searchCluster={search_cluster}&includeExtendedCounters=false&inventoryItemId={inventory_item_id}" # noqa : E501 - ) as response: + async with ( + ClientSession() as session, + session.get( + f"https://create.kahoot.it/rest/kahoots/?query={query}&limit={limit}&cursor={cursor}&searchCluster={search_cluster}&includeExtendedCounters=false&inventoryItemId={inventory_item_id}" # noqa : E501 + ) as response, + ): return _Response(**await response.json()) diff --git a/classquiz/routers/eximport.py b/classquiz/routers/eximport.py index 641be116..6c289d37 100644 --- a/classquiz/routers/eximport.py +++ b/classquiz/routers/eximport.py @@ -62,9 +62,10 @@ async def export_quiz(quiz_id: uuid.UUID, user: User = Depends(get_current_user) for image_key in image_urls: bin_data = bin_data + image_delimiter + str(image_key).encode("utf-8") + image_index_delimiter image_data = None - async with ClientSession() as session, session.get( - f"{settings.root_address}/api/v1/storage/download/{image_urls[image_key]}" - ) as resp: + async with ( + ClientSession() as session, + session.get(f"{settings.root_address}/api/v1/storage/download/{image_urls[image_key]}") as resp, + ): image_data = await resp.read() bin_data = bin_data + image_data