Created
December 21, 2022 20:40
-
-
Save doxyf/018451cf14d08c70781fea9599c50332 to your computer and use it in GitHub Desktop.
Without error handling!
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
const axios = require('axios'); | |
const process = require('process'); | |
var kahid = process.argv[2]; | |
if(!kahid) throw new Error('Please enter valid Kahoot ID (not room ID)') | |
async function main(){ | |
let r = await axios.get(`https://create.kahoot.it/rest/kahoots/${kahid}/card/?includeKahoot=true`); | |
let parsed = parseQuestions(r.data.kahoot.questions); | |
parsed.forEach(res => { | |
console.log(`[${res.qpos}] Q: ${res.question} | A: ${res.answ} | (That's position ${res.pos})`); | |
}); | |
}; | |
main(); | |
function parseQuestions(qJson){ | |
let answ = []; | |
qJson.forEach((partial, i) => { | |
if(partial.type == 'content') return; | |
partial.choices.forEach((val, j) => { | |
if(val.correct) answ.push({qpos: i, question: partial.question, pos: j, answ: val.answer}); | |
}); | |
}); | |
return answ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment