Last active
February 6, 2024 13:04
-
-
Save krmax44/60836873e71b45a18c5a58c2aa7aef13 to your computer and use it in GitHub Desktop.
Export Kahoot quizes to Anki text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "4cb55a75-9ffc-497b-b3bb-9b35fb1d9851", | |
"metadata": { | |
"collapsed": true, | |
"jupyter": { | |
"outputs_hidden": true | |
}, | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"!pip3 install requests" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "6b38669d-b1f7-4b69-9c46-78918115b50d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests, csv" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "54b99a7d-e200-4ea7-b4d5-7b183680362e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# enter kahoot uuids from url: https://create.kahoot.it/details/<uuid>\n", | |
"\n", | |
"kahoots = [\n", | |
" \"<uuid>\",\n", | |
" \"<uuid>\"\n", | |
"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "0a794fad-35f5-4375-96f8-1dfb663d102a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def listify(list, list_type='ol'):\n", | |
" if len(list) == 1:\n", | |
" return list[0]\n", | |
"\n", | |
" list_elements = [f\"<li>{el}</li>\" for el in list]\n", | |
" return f\"<{list_type}>{''.join(list_elements)}</{list_type}>\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "369b869b-1845-45e4-84a0-c41fed11e1ff", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"96" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"q = 0\n", | |
"\n", | |
"for kahoot in kahoots:\n", | |
" url = f\"https://create.kahoot.it/rest/kahoots/{kahoot}/card/?includeKahoot=true\"\n", | |
" r = requests.get(url)\n", | |
" data = r.json()\n", | |
" slug = data[\"kahoot\"][\"slug\"]\n", | |
" \n", | |
" with open(f\"{slug}.csv\", \"w\", newline=\"\") as csvfile:\n", | |
" writer = csv.writer(csvfile)\n", | |
" writer.writerow([\"#separator: Comma\"])\n", | |
" writer.writerow([f\"#tags: {slug}\"])\n", | |
" questions = [question for question in data[\"kahoot\"][\"questions\"] if question[\"type\"] == \"quiz\"]\n", | |
" for question in questions:\n", | |
" q += 1\n", | |
" answers = [choice[\"answer\"] for choice in question[\"choices\"]]\n", | |
" correct_answers = [f\"{i+1}: {choice['answer']}\" for (i, choice) in enumerate(question[\"choices\"]) if choice[\"correct\"]]\n", | |
" writer.writerow([\n", | |
" question[\"question\"],\n", | |
" listify(answers),\n", | |
" listify(correct_answers, list_type='li'),\n", | |
" ])\n", | |
"\n", | |
"q" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "venv", | |
"language": "python", | |
"name": "venv" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment