diff --git a/classquiz/kahoot_importer/__init__.py b/classquiz/kahoot_importer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/classquiz/kahoot_importer/get.py b/classquiz/kahoot_importer/get.py new file mode 100644 index 0000000..6124a99 --- /dev/null +++ b/classquiz/kahoot_importer/get.py @@ -0,0 +1,116 @@ +from uuid import UUID +from typing import List, Any, Optional +from aiohttp import ClientSession + +from pydantic import BaseModel + + +class _Access(BaseModel): + groupRead: List[Any | None] + folderGroupIds: List[Any | None] + + +class _CoverMetadata(BaseModel): + id: UUID + resources: str | None + + +class _CreatorAvatar(BaseModel): + url: str + id: UUID | None + type: str | None + bitmojiAvatarId: str | None + altText: str | None + contentType: str | None + width: int | None + height: int | None + + +class _LastEdit(BaseModel): + editorUserId: UUID + editorUsername: str + editTimestamp: int + + +class _ImageMetadata(BaseModel): + id: UUID + content_type: Optional[str] + width: Optional[int] + height: Optional[int] + resources: Optional[str] + + +class _SampleQuestion(BaseModel): + image: str | None + imageMetadata: _ImageMetadata | None + title: str + type: str + time: int + + +class _Card(BaseModel): + type: str + title: str + description: str + slug: str + cover: str | None + coverMetadata: _CoverMetadata | dict[None, None] + draftExists: bool + inventoryItemIds: List[Any] + number_of_questions: int + creator: UUID + creator_username: str + creator_avatar: _CreatorAvatar | dict[None, None] | None + badges: List[str] + visibility: int + locked: bool + writeProtection: bool + last_edit: _LastEdit | None + featured: bool + young_featured: bool + sponsored: bool + draft: bool + combined: bool + compatibility_level: int + sample_questions: List[_SampleQuestion] + number_of_plays: int + number_of_players: int + total_favourites: int + question_types: List[str] + created: int + modified: int + access: _Access + duplication_disabled: bool + uuid: UUID + + +class _Entity(BaseModel): + card: _Card + + +class _Response(BaseModel): + entities: List[_Entity] + totalHits: int + cursor: int + pageTimestamp: int + + +async def get(query: str | None, limit: int | None = 9, cursor: int | None = 1, + search_cluster: int | None = 1, inventory_item_id: str | None = "ANY") -> _Response: + """ + + :param inventory_item_id: I dkon't know + :param search_cluster: Doesn't seeem to matter + :param cursor: The position in the result-list (page) + :param query: The search query + :param limit: Less or equals 100 + :return: + """ + async with ClientSession() as session: + 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}" + + ) as response: + print( + f"https://create.kahoot.it/rest/kahoots/?query={query}&limit={limit}&cursor={cursor}&searchCluster={search_cluster}&includeExtendedCounters=false&inventoryItemId={inventory_item_id}") + return _Response(**await response.json()) diff --git a/classquiz/kahoot_importer/import.py b/classquiz/kahoot_importer/import.py new file mode 100644 index 0000000..9f2c1bc --- /dev/null +++ b/classquiz/kahoot_importer/import.py @@ -0,0 +1,3 @@ +from aiohttp import ClientSession +import pydantic + diff --git a/classquiz/kahoot_importer/search.py b/classquiz/kahoot_importer/search.py new file mode 100644 index 0000000..e69de29 diff --git a/classquiz/kahoot_importer/test_get.py b/classquiz/kahoot_importer/test_get.py new file mode 100644 index 0000000..14c4325 --- /dev/null +++ b/classquiz/kahoot_importer/test_get.py @@ -0,0 +1,11 @@ +from unittest import IsolatedAsyncioTestCase +from get import get + + +class Test(IsolatedAsyncioTestCase): + async def test_get(self): + res = await get(query="Python") + self.assertEqual(len(res.entities), 9) + await get(query="Test Quiz") + await get(query="Biologie") + await get(query="Chemie") \ No newline at end of file