-
Notifications
You must be signed in to change notification settings - Fork 3
/
edugameconvert.html
727 lines (660 loc) · 33.1 KB
/
edugameconvert.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
<!DOCTYPE html>
<html lang="en">
<head>
<title>edugameconvert - Convert questions between educational game platforms</title>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/brython@3/brython.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/brython@3/brython_stdlib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/zipcelx@1.6.2/lib/standalone.min.js"></script>
<style>
html, body, div {
margin: 0px;
}
#site {
height: 100vh;
height: 100dvh;
display: flex;
flex-direction: column;
}
#tutorial {
display: block;
}
h1 {
font-family: Arial, sans-serif;
font-size: 36px;
font-weight: bold;
margin: 0px 10px;
flex: 1;
}
pre {
font-family: Arial, sans-serif;
font-size: 24px;
margin: 20px;
line-height: 1.5;
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
p {
margin: 0px;
padding: 0px;
display: inline;
}
a, a:visited {
text-decoration: underline;
color: blue;
}
input, button, label, span {
font-family: Arial, sans-serif;
font-size: 32px;
color: black;
line-height: normal;
text-decoration: none;
font-weight: normal;
padding: 0px;
}
input, button {
border-radius: 0px;
background-color: #f8f8f8;
-webkit-appearance: none;
border: 1px solid gray;
}
::placeholder {
color: gray;
opacity: 1;
}
::-ms-input-placeholder {
color: gray;
}
span, label, button {
margin: 0px 10px;
}
#form {
display: flex;
flex-direction: column;
}
#platform, #header, #footer {
display: flex;
flex-direction: row;
margin: 20px 10px;
}
#platform {
overflow-x: auto;
}
#site button {
flex: 1;
}
#help1, #help2, #report {
margin: 0px 10px;
padding: 5px 7px;
font-size: 20px;
}
#game_url {
margin: 20px 20px 0px;
padding: 5px 7px;
font-size: 28px;
display: block;
flex: 1;
}
input[type="radio"] {
width: 0px;
height: 0px;
border: 0px;
margin: 0px;
padding: 0px;
}
input[type="radio"]:checked + label {
background-color: lightcoral;
}
textarea {
font-family: monospace;
font-size: 20px;
margin: 0px 20px;
padding: 10px;
color: darkred;
line-height: normal;
flex: 1;
resize: none;
word-break: break-all;
overflow-y: scroll;
}
</style>
</head>
<body onload="brython (0)">
<noscript>
<p>JavaScript is required to use this website.</p>
</noscript>
<div id="site">
<form action = "javascript:void (0);" id="form">
<input type="text" id="game_url" placeholder="Paste URL of game here:" required>
<div id="platform">
<span>To:</span>
<input type="radio" name="platform" id="kahoot" value="kahoot" checked>
<label for="kahoot">Kahoot</label>
<input type="radio" name="platform" id="quizizz" value="quizizz">
<label for="quizizz">Quizizz</label>
<input type="radio" name="platform" id="blooket" value="blooket">
<label for="blooket">Blooket</label>
<input type="radio" name="platform" id="gimkit" value="gimkit">
<label for="gimkit">Gimkit</label>
<input type="radio" name="platform" id="classquiz" value="classquiz">
<label for="classquiz">ClassQuiz</label>
<button type="submit"> Convert! </button>
</div>
</form>
<textarea id="output" readonly>
Welcome to edugameconvert, a tool to convert questions between educational game platforms!
The current supported platforms are Kahoot, Quizizz, Blooket, Gimkit, and ClassQuiz.
Paste the URL of a question set in the box above, select the platform to convert to, and click "Convert!"
A file would be downloaded with the converted questions, which you can import into the selected platform.
Information and warnings would be displayed here. Enjoy!
Each platform has different import limitations. The tool would attempt to convert as much as possible.
Supported question types and fields when exporting to each platform are listed below:
- Kahoot: MCQ (max 4 answers), time limit (limited options)
- Quizizz: MCQ (max 5 answers), time limit (limited options), Typing (max 5 answers), Image (URL)
- Blooket: MCQ (max 4 answers), time limit (max 300 seconds), Typing (max 4 answers)
- Gimkit: MCQ (max 4 answers, only 1 correct), no time limit
- ClassQuiz: MCQ (max 4 answers), time limit (max 999 seconds), Typing (max 4 answers)
</textarea>
<div id="footer">
<button id="help1">Help</button>
<button id="report" onclick="location.href='https://github.com/CyrilSLi/cyrilsli.github.io/blob/main/edugameconvert.html';">GitHub repo / Report a bug</button>
</div>
</div>
<div id="tutorial">
<div id="header">
<button id="help2">Back</button>
<h1>How to use edugameconvert</h1>
</div>
<pre>
Please read the text on the main page for a quick description and the limitations of each platform.
If you have an issue or want to suggest a platform, please raise an issue on the GitHub repository.
1. Paste the URL of a question set from Kahoot, Quizizz, or Blooket into the top box.
	- The set must be public and cannot be a game or homework link (i.e. the list of questions must be visible).
	- Example URLs (your link does not have to be in this exact format, it just must contain the game ID):
		- Kahoot: <p style="color: blue;">https://create.kahoot.it/details/a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6</p>
		- Quizizz: <p style="color: blue;">https://quizizz.com/admin/quiz/a1b2c3d4e5f6a1b2c3d4e5f6/game-name</p>
		- Blooket: <p style="color: blue;">https://dashboard.blooket.com/set/a1b2c3d4e5f6a1b2c3d4e5f6</p>
		- Gimkit: <p style="color: blue;">https://www.gimkit.com/view/a1b2c3d4e5f6a1b2c3d4e5f6</p>
		- ClassQuiz: <p style="color: blue;">https://classquiz.de/view/a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6</p>
2. Select the platform you want to convert the questions to.
	- <b>Please check the limitations on question types and fields for each platform on the main page.</b>
	- <i>Tip: Even though some button outlines are not visible, everything can be selected using the keyboard.</i>
3. Click the <b>Convert!</b> button and save the generated .xlsx or .csv (depending on the platform) file.
	- If no file is generated, please raise an issue on the GitHub repository with the following information:
		- Question set URL
		- Platform you tried to convert to
		- Information displayed in the output box
		- Any errors and the game JSON (if available) displayed in the browser console
	- The output box displays import & export statistics and any warnings generated during the conversion.
		- A count is shown for each supported question type: MCQ, MSQ (multiselect MCQ), and Typing.
4. Import the file into the selected platform.
	- <b>Remember to check questions and answers after importing!</b> Please report any issues you encounter.
	- Import guides (do not use the templates provided in the guides, upload the generated file directly):
		- <a href="https://support.kahoot.com/hc/en-us/articles/115002812547-How-to-import-questions-from-a-spreadsheet-to-your-kahoot" target="_blank">Kahoot import guide</a>
		- <a href="https://support.quizizz.com/hc/en-us/articles/115003688491-Import-an-Assessment-Quiz-From-a-Spreadsheet" target="_blank">Quizizz import guide</a>
		- <a href="https://help.blooket.com/hc/en-us/articles/16002377931543-How-to-Import-Questions-from-a-Spreadsheet-into-Blooket" target="_blank">Blooket import guide</a>
		- <a href="https://help.gimkit.com/en/article/create-a-kit-with-a-csv-file-wv72i9" target="_blank">Gimkit import guide</a>
		- ClassQuiz: Upload the .cqa file to Homepage -> Import -> "A ClassQuiz-Quiz"
<b>CORS Proxy</b>
As this tool runs entirely in the browser, fetching game data from other websites is restricted by <a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing" target="_blank">CORS</a>.
It uses <a href="https://corsproxy.io/" target="_blank">corsproxy.io</a> by default to bypass this restriction, however this may be blocked on certain networks.
If you wish to use another proxy, set the <b>cors_url</b> query parameter to a URL prefix (e.g. <a href="?cors_url=https://cors-anywhere.herokuapp.com/" target="_self">cors-anywhere</a>).
If you have a CORS bypass extension installed (<a href="https://chromewebstore.google.com/detail/cors-unblock/lfhmikememgdcahcdlaciloancbhjino" target="_blank">example</a>), disable the proxy by <a href="?cors_url=" target="_self">setting an empty value</a>.
<b>This tool is not sponsored by or affiliated with any proxies, extensions, or platforms mentioned.</b>
</pre>
</div>
<script type = "text/python">
from browser import document, html, ajax, window
import json, html as py_html # Avoid name conflict with Brython's html module
from html.parser import HTMLParser
def log (msg):
document ["output"].value += msg + "\n"
document ["output"].scrollTop = document ["output"].scrollHeight
def show_metadata (title, creator, description, num_qs, platform):
log (f'{platform} game "{title}" by {creator} with {num_qs} question(s)') # Description is currently not used
def show_warning (question, message, level = "WARNING"):
log (f'{level} - Question {question + 1}: {message}')
def show_stats (msg, stats):
stats ["Total"] = sum (stats.values ())
log (msg.format (stats = ", ".join (f"{v} {k}" for k, v in sorted (stats.items (), key = lambda x: x [1]))))
class Filter (HTMLParser):
text = ""
def handle_data (self, data):
self.text += data
def strip_html (text):
if type (text) in (list, tuple):
out = []
for i in text:
f = Filter ()
f.feed (i)
out.append (py_html.unescape (f.text))
return out
f = Filter ()
f.feed (text)
return py_html.unescape (f.text)
document ["tutorial"].style.display = "none"
def toggle_help (ev):
for i in (document ["site"], document ["tutorial"]):
i.style.display = {"none": "", "": "none"} [i.style.display]
document ["help1"].bind ("click", toggle_help)
document ["help2"].bind ("click", toggle_help)
def kahoot_import (game):
show_metadata (game ["title"], game ["creator_username"], game ["description"], len (game ["questions"]), "Kahoot")
export = []
for j, i in enumerate (game ["questions"]):
if i ["type"] not in ("quiz", "multiple_select_quiz", "open_ended"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
export.append (None) # Keep index consistent
continue
question = {
"question": strip_html (i ["question"]),
"type": {"quiz": "MCQ", "multiple_select_quiz": "MSQ", "open_ended": "Typing"} [i ["type"]],
"time": i ["time"] // 1000,
"image": i ["image"] if "image" in i else ""
}
answers, correct = [], []
for k in i ["choices"]:
if "answer" in k:
answers.append (k ["answer"])
elif "image" in k and "altText" in k ["image"]:
answers.append (k ["image"] ["altText"])
show_warning (j, f"Image answer not supported, using alt text {k ["image"] ["altText"]}")
else:
show_warning (j, "Non-text answer not supported, skipping")
export.append (None) # Keep index consistent
break
if k ["correct"]:
correct.append (len (answers)) # 1-indexed
else:
question ["answers"], question ["correct"] = answers, correct
export.append (question)
return export
def quizizz_import (game):
game = game ["data"] ["quiz"]
show_metadata (game ["info"] ["name"], game ["createdBy"] ["local"] ["username"], "", len (game ["info"] ["questions"]), "Quizizz")
game = game ["info"] ["questions"]
export = []
for j, i in enumerate (game):
if i ["type"] not in ("MCQ", "MSQ", "BLANK"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
export.append (None) # Keep index consistent
continue
question = {
"question": strip_html (i ["structure"] ["query"] ["text"]),
"type": {"MCQ": "MCQ", "MSQ": "MSQ", "BLANK": "Typing"} [i ["type"]],
"time": i ["time"] // 1000,
"image": i ["structure"] ["query"] ["media"] [0] ["url"] if i ["structure"] ["query"] ["media"] else "",
"correct": []
}
if type (i ["structure"] ["answer"]) == int:
if i ["structure"] ["answer"] > -1:
question ["correct"] = [i ["structure"] ["answer"] + 1]
else:
question ["correct"] = [k + 1 for k in i ["structure"] ["answer"]]
answers = []
for k in i ["structure"] ["options"]:
if k ["type"] != "text":
show_warning (j, "Non-text answer not supported, skipping")
export.append (None) # Keep index consistent
break
answers.append (strip_html (k ["text"]))
else:
if question ["type"] == "Typing":
question ["correct"] = list (range (1, len (answers) + 1))
elif not len (question ["correct"]):
show_warning (j, "No correct answer found (likely a poll), skipping")
continue
question ["answers"] = answers
export.append (question)
return export
def blooket_import (game):
show_metadata (game ["title"], game ["author"], game ["desc"], len (game ["questions"]), "Blooket")
export = []
for i in game ["questions"]:
question = {
"question": i ["question"],
"type": {"mc": "MCQ", "typing": "Typing", "": "MCQ"} [i ["qType"]],
"answers": i ["answers"],
"correct": [i ["answers"].index (j) + 1 for j in i ["correctAnswers"]],
"time": i ["timeLimit"],
"image": i ["image"] ["url"] if "image" in i else ""
}
if question ["type"] == "Typing":
question ["correct"] = list (range (1, len (question ["answers"]) + 1))
export.append (question)
return export
def gimkit_import (game):
show_metadata (game ["kit"] ["title"], game ["creator"] ["name"], "", len (game ["kit"] ["questions"]), "Gimkit")
export = []
for i in game ["kit"] ["questions"]:
question = {
"question": i ["text"],
"type": {"mc": "MCQ", "text": "Typing"} [i ["type"]],
"answers": [j ["text"] for j in i ["answers"]],
"correct": [k + 1 for k, j in enumerate (i ["answers"]) if j ["correct"]],
"time": 20, # No time limit in Gimkit
"image": i ["image"] if "image" in i else ""
}
export.append (question)
return export
def classquiz_import (game):
game = game [1] ["data"] ["quiz"]
show_metadata (game ["title"], game ["user_id"] ["username"], game ["description"], len (game ["questions"]), "ClassQuiz")
export = []
for j, i in enumerate (game ["questions"]):
if i ["type"] not in ("ABCD", "CHECK", "TEXT"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
export.append (None) # Keep index consistent
continue
question = {
"question": i ["question"],
"type": {"ABCD": "MCQ", "CHECK": "MSQ", "TEXT": "Typing"} [i ["type"]],
"answers": [k ["answer"] for k in i ["answers"]],
"time": int (i ["time"]),
"image": f"https://classquiz.de/api/v1/storage/download/{i ['image']}" if i ["image"] else "",
"correct": []
}
if question ["type"] == "Typing":
question ["correct"] = list (range (1, len (question ["answers"]) + 1))
else:
question ["correct"] = [k + 1 for k, j in enumerate (i ["answers"]) if j ["right"]]
export.append (question)
return export
def add_row (values):
return [{"value": i, "type": "string"} for i in values]
def remove_answers (num, question, max_answers, mult_correct = True):
if not mult_correct and len (question ["correct"]) > 1:
show_warning (num, "Multiple correct answers not supported, skipping")
return False # continue loop
elif not len (question ["correct"]):
show_warning (num, "No correct answer found, skipping")
return False
if len (question ["answers"]) > max_answers:
if max (question ["correct"]) <= max_answers:
question ["answers"] = question ["answers"] [ : max_answers]
show_warning (num, f"More than maximum of {max_answers} answers, removing excess answers", "INFO")
else:
show_warning (num, f"More than maximum of {max_answers} answers and correct answer is outside range, skipping")
return False
return True # Success
def kahoot_export (game):
template = {
"filename": "kahoot-export",
"sheet": {
"data": [
[{
"value": "Question - max 120 characters",
"type": "string"
}, {
"value": "Answer 1 - max 75 characters",
"type": "string"
}, {
"value": "Answer 2 - max 75 characters",
"type": "string"
}, {
"value": "Answer 3 - max 75 characters",
"type": "string"
}, {
"value": "Answer 4 - max 75 characters",
"type": "string"
}, {
"value": "Time limit (sec) – 5, 10, 20, 30, 60, 90, 120, or 240 secs",
"type": "string"
}, {
"value": "Correct answer(s) - choose at least one",
"type": "string"
}]
]
}
}
stats = {}
for j, i in enumerate (game):
if not i:
continue # Skip unsupported question types
question = [i ["question"] [ : 120]]
if i ["type"] not in ("MCQ", "MSQ"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
continue
if not remove_answers (j, i, 4):
continue
question.extend ([j [ : 75] for j in i ["answers"]] + [""] * (4 - len (i ["answers"])))
question.append (str (min ((5, 10, 20, 30, 45, 60, 90, 120, 180, 240), key = lambda x: abs (x - i ["time"]))))
question.append (",".join (str (j) for j in i ["correct"]))
template ["sheet"] ["data"].append (add_row (question))
stats [i ["type"]] = stats.get (i ["type"], 0) + 1
window.zipcelx (template)
return stats
def quizizz_export (game):
template = {
"filename": "quizizz-export",
"sheet": {
"data": [
[{
"value": "Question Text",
"type": "string"
}, {
"value": "Question Type",
"type": "string"
}, {
"value": "Option 1",
"type": "string"
}, {
"value": "Option 2",
"type": "string"
}, {
"value": "Option 3",
"type": "string"
}, {
"value": "Option 4",
"type": "string"
}, {
"value": "Option 5",
"type": "string"
}, {
"value": "Correct Answer",
"type": "string"
}, {
"value": "Time in seconds",
"type": "string"
}, {
"value": "Image Link",
"type": "string"
}]
]
}
}
stats = {}
for j, i in enumerate (game):
if not i:
continue # Skip unsupported question types
question = [i ["question"]]
if i ["type"] in ("MCQ", "MSQ"):
if len (i ["correct"]) > 1:
question.append ("Checkbox")
else:
question.append ("Multiple Choice")
elif i ["type"] == "Typing":
question.append ("Fill-in-the-Blank")
else:
show_warning (j, f"Question type {i ['type']} not supported, skipping")
continue
if not remove_answers (j, i, 5):
continue
question.extend (i ["answers"] + [""] * (5 - len (i ["answers"])))
question.append (",".join (str (j) for j in i ["correct"]))
question.extend ([str (i ["time"]), i ["image"]])
template ["sheet"] ["data"].append (add_row (question))
stats [i ["type"]] = stats.get (i ["type"], 0) + 1
window.zipcelx (template)
return stats
def blooket_export (game):
template = ',,,,,,,,,\n,Question Text,Answer 1,Answer 2,"Answer 3\n(Optional)","Answer 4\n(Optional)","Time Limit (sec)\n(Max: 300 seconds)","Correct Answer(s)\n(Only include Answer #)",,\n'
escape = lambda x: f"\"{x.replace ('"', '""')}\""
stats = {}
for j, i in enumerate (game):
if not i:
continue # Skip unsupported question types
question = ["", escape (i ["question"])]
if i ["type"] not in ("MCQ", "MSQ", "Typing"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
continue
if not remove_answers (j, i, 4):
continue
question.extend ([escape (j) for j in i ["answers"]] + [""] * (4 - len (i ["answers"])))
question.append (str (min (i ["time"], 300)))
question.append (f'"{",".join (str (j) for j in i ["correct"])}"')
question.append ("")
question.append ("typing" if i ["type"] == "Typing" else "")
template += ",".join (question) + "\n"
stats [i ["type"]] = stats.get (i ["type"], 0) + 1
blob = window.Blob.new ([template], {"type": "text/csv"})
link = html.A ("", href = window.URL.createObjectURL (blob), download = "blooket-export.csv")
link.click ()
return stats
def gimkit_export (game):
template = ',,,,\nQuestion,Correct Answer,Incorrect Answer 1,Incorrect Answer 2,Incorrect Answer 3\n'
escape = lambda x: f"\"{x.replace ('"', '""')}\""
stats = {}
for j, i in enumerate (game):
if not i:
continue # Skip unsupported question types
question = [escape (i ["question"])]
if i ["type"] not in ("MCQ", "MSQ"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
continue
if not remove_answers (j, i, 4, mult_correct = False):
continue
# Move correct answer to front
correct = i ["correct"] [0] - 1
i ["answers"] = [i ["answers"] [correct]] + [j for k, j in enumerate (i ["answers"]) if k != correct]
i ["correct"] = [1]
question.extend ([escape (j) for j in i ["answers"]] + [""] * (4 - len (i ["answers"])))
template += ",".join (question) + "\n"
stats [i ["type"]] = stats.get (i ["type"], 0) + 1
blob = window.Blob.new ([template], {"type": "text/csv"})
link = html.A ("", href = window.URL.createObjectURL (blob), download = "gimkit-export.csv")
link.click ()
return stats
def classquiz_export (game):
import gzip
template = {
"public": True,
"title": "ClassQuiz Export",
"description": "Exported from https://cyrilsli.github.io/edugameconvert.html",
"created_at": "1970-01-01T00:00:00.000000",
"updated_at": "1970-01-01T00:00:00.000000",
"questions": [],
"imported_from_kahoot": False,
"cover_image": None,
"background_color": None,
"background_image": None,
"kahoot_id": None,
"likes": 0,
"dislikes": 0,
"plays": 0,
"views": 0,
"mod_rating": None,
"gameresultss": [],
"ratings": [],
"storageitems": []
}
stats = {}
for j, i in enumerate (game):
if not i:
continue # Skip unsupported question types
if i ["type"] not in ("MCQ", "MSQ", "Typing"):
show_warning (j, f"Question type {i ['type']} not supported, skipping")
continue
if not remove_answers (j, i, 4):
continue
question = {
"question": i ["question"],
"time": str (i ["time"]),
"type": {"MCQ": "ABCD", "MSQ": "CHECK", "Typing": "TEXT"} [i ["type"]],
"answers": [],
"image": None
}
if i ["type"] != "Typing":
question ["answers"] = [{
"right": l + 1 in i ["correct"],
"answer": k,
"color": "#FFFFFF"
} for l, k in enumerate (i ["answers"])]
else:
question ["answers"] = [{
"answer": k,
"case_sensitive": False
} for k in i ["answers"]]
template ["questions"].append (question)
stats [i ["type"]] = stats.get (i ["type"], 0) + 1
# https://github.com/mawoka-myblock/ClassQuiz/blob/master/classquiz/routers/cqa-file-format.md
game = gzip.compress (json.dumps (template).encode ("utf-8"), compresslevel = 9) + bytes.fromhex ("c7c7c700")
game = window.Uint8Array.new ([int (i) for i in game])
blob = window.Blob.new ([game], {"type": "application/octet-stream"})
link = html.A ("", href = window.URL.createObjectURL (blob), download = "classquiz-export.cqa")
link.click ()
return stats
def convert (_):
import re
game_url = document ["game_url"].value
platform_out = document.querySelector ('input[name="platform"]:checked').value
id_regex = r"[0-9a-f]{24}" # 24-character hex
document ["output"].value = ""
if "kahoot.it" in game_url:
id_regex = r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" # UUID
platform_in = "kahoot"
elif "quizizz.com" in game_url:
game_id = game_url.split ("/") [-1]
platform_in = "quizizz"
elif "blooket.com" in game_url:
game_id = game_url.split ("/") [-1]
platform_in = "blooket"
elif "gimkit.com" in game_url:
game_id = game_url.split ("/") [-1]
platform_in = "gimkit"
elif "classquiz.de" in game_url:
id_regex = r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" # UUID
platform_in = "classquiz"
else:
log (f"Invalid game URL: {game_url}")
return
game_id = re.search (id_regex, game_url)
if game_id is None:
log (f"Cannot find game ID in URL: {game_url}")
return
game_id = game_id [0]
converters = {
"kahoot": (kahoot_import, f"https://create.kahoot.it/rest/kahoots/{game_id}", kahoot_export),
"quizizz": (quizizz_import, f"https://quizizz.com/_quizserver/main/v2/quiz/{game_id}", quizizz_export),
"blooket": (blooket_import, f"https://dashboard.blooket.com/api/games?gameId={game_id}", blooket_export),
"gimkit": (gimkit_import, f"https://www.gimkit.com/api/games/fetch/{game_id}", gimkit_export),
"classquiz": (classquiz_import, f"https://classquiz.de/view/{game_id}", classquiz_export)
}
cors_proxy = document.query.getvalue ("cors_url")
if cors_proxy is None:
cors_proxy = "https://corsproxy.io/?url=" # Default CORS proxy
def callback (req):
if req.status != 200:
log (f"HTTP Error {req.status}")
log ("Please check the game URL and try again.")
return
if platform_in == "classquiz":
game = window.eval (req.text.split ("const data = ") [-1].split (";") [0]) # Extract JSON from html
else:
game = json.loads (req.text)
log (f"\n>>> Running {converters [platform_in] [0].__name__}()")
game = converters [platform_in] [0] (game)
show_stats ("Imported {stats}\n", {i: len ([j for j in game if j and j ["type"] == i]) for i in set (j ["type"] for j in game if j)}) # Count question types
window.console.log (json.dumps (game, indent = 4, ensure_ascii = False))
log (f">>> Running {converters [platform_out] [2].__name__}()")
show_stats ("Exported {stats}\n", converters [platform_out] [2] (game))
log (">>> Conversion complete, saving to file")
log (">>> Fetching game data")
ajax.get (cors_proxy + converters [platform_in] [1], oncomplete = callback, cache = True)
document ["form"].bind ("submit", convert)
</script>
</body>
</html>