🚨 Merged with-statements
This commit is contained in:
@@ -10,8 +10,9 @@ class _Response(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
async def get(game_id: str) -> _Response | None:
|
async def get(game_id: str) -> _Response | None:
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session, session.get(
|
||||||
async with session.get(f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true") as response:
|
f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true"
|
||||||
|
) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
return _Response(**await response.json())
|
return _Response(**await response.json())
|
||||||
elif response.status == 404:
|
elif response.status == 404:
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ async def search(
|
|||||||
:param limit: Less or equals 100
|
:param limit: Less or equals 100
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session, session.get(
|
||||||
async with 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
|
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:
|
) as response:
|
||||||
return _Response(**await response.json())
|
return _Response(**await response.json())
|
||||||
|
|||||||
@@ -132,8 +132,6 @@ async def update_quiz(quiz_id: str, quiz_input: QuizInput, user: User = Depends(
|
|||||||
if quiz is None:
|
if quiz is None:
|
||||||
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
|
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
|
||||||
else:
|
else:
|
||||||
# print(quiz_input)
|
|
||||||
# print(quiz)
|
|
||||||
quiz_input.description = bleach.clean(quiz_input.description, tags=[], strip=True)
|
quiz_input.description = bleach.clean(quiz_input.description, tags=[], strip=True)
|
||||||
quiz_input.title = bleach.clean(quiz_input.title, tags=[], strip=True)
|
quiz_input.title = bleach.clean(quiz_input.title, tags=[], strip=True)
|
||||||
meilisearch.index(settings.meilisearch_index).update_documents([await get_meili_data(quiz)])
|
meilisearch.index(settings.meilisearch_index).update_documents([await get_meili_data(quiz)])
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ class IpResponse(BaseModel):
|
|||||||
|
|
||||||
@router.get("/ip-lookup/{ip}", response_model=IpResponse)
|
@router.get("/ip-lookup/{ip}", response_model=IpResponse)
|
||||||
async def get_ip_data(ip: str, _: User = Depends(get_current_user)):
|
async def get_ip_data(ip: str, _: User = Depends(get_current_user)):
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session, session.get(f"http://ip-api.com/json/{ip}") as response:
|
||||||
async with session.get(f"http://ip-api.com/json/{ip}") as response:
|
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
try:
|
try:
|
||||||
return IpResponse(**data)
|
return IpResponse(**data)
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ class DetaStorage:
|
|||||||
:param file_name: The name of the file to be downloaded
|
:param file_name: The name of the file to be downloaded
|
||||||
:return: Either bytes f successfull download or None if failed
|
:return: Either bytes f successfull download or None if failed
|
||||||
"""
|
"""
|
||||||
async with ClientSession(headers=self.headers) as session:
|
async with ClientSession(headers=self.headers) as session, session.get(
|
||||||
async with session.get(f"{self.deta_url}/files/download?name={file_name}") as response:
|
f"{self.deta_url}/files/download?name={file_name}"
|
||||||
|
) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
return BytesIO(await response.read())
|
return BytesIO(await response.read())
|
||||||
elif response.status == 404:
|
elif response.status == 404:
|
||||||
@@ -33,16 +34,18 @@ class DetaStorage:
|
|||||||
:param file_name: The name of the file
|
:param file_name: The name of the file
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
async with ClientSession(headers=self.headers) as session:
|
async with ClientSession(headers=self.headers) as session, session.post(
|
||||||
async with session.post(f"{self.deta_url}/files?name={file_name}", data=file) as response:
|
f"{self.deta_url}/files?name={file_name}", data=file
|
||||||
|
) as response:
|
||||||
if response.status == 201:
|
if response.status == 201:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
raise Exception("Upload failed")
|
raise Exception("Upload failed")
|
||||||
|
|
||||||
async def delete(self, file_names: [str]) -> None:
|
async def delete(self, file_names: [str]) -> None:
|
||||||
async with ClientSession(headers=self.headers) as session:
|
async with ClientSession(headers=self.headers) as session, session.delete(
|
||||||
async with session.delete(f"{self.deta_url}/files", json={"names": file_names}) as response:
|
f"{self.deta_url}/files", json={"names": file_names}
|
||||||
|
) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user