Skip to content

Commit

Permalink
Merge pull request #335 from mawoka-myblock/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
mawoka-myblock authored Jan 29, 2024
2 parents b9dee77 + 73c29d0 commit 530cc5d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions classquiz/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions classquiz/helpers/pixabay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions classquiz/kahoot_importer/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions classquiz/kahoot_importer/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
7 changes: 4 additions & 3 deletions classquiz/routers/eximport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 530cc5d

Please sign in to comment.