javascript(quizizz-hack): feat: cli
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
commit
71cb49a7e4
1
javascript/quizizz-hack/.gitignore
vendored
Normal file
1
javascript/quizizz-hack/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules
|
1
javascript/quizizz-hack/file.json
Normal file
1
javascript/quizizz-hack/file.json
Normal file
File diff suppressed because one or more lines are too long
109
javascript/quizizz-hack/index.js
Normal file
109
javascript/quizizz-hack/index.js
Normal file
|
@ -0,0 +1,109 @@
|
|||
const fetch = require("node-fetch");
|
||||
const chalk = require("chalk");
|
||||
const { default: readline } = require("readline-promise");
|
||||
|
||||
const id = process.argv[2];
|
||||
|
||||
const rlp = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: true,
|
||||
});
|
||||
|
||||
const tags = ["p", "strong", "em"];
|
||||
|
||||
function removeTags(input) {
|
||||
let copy = input.replace('"', '\\"');
|
||||
|
||||
for (const tag of tags)
|
||||
copy = copy.replace(`<${tag}>`, "").replace(`</${tag}>`, "");
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
// Here is the function to parse the json object.
|
||||
// It returns object with key/value pair where key is the question and value is the answer
|
||||
function parseFile(fileObject) {
|
||||
const allAnswers = {};
|
||||
|
||||
for (const question of fileObject.data.quiz.info.questions) {
|
||||
let answer;
|
||||
|
||||
if (question.type === "MCQ") {
|
||||
if (question.structure.options[question.structure.answer].text == "") {
|
||||
answer =
|
||||
question.structure.options[question.structure.answer].media[0].url;
|
||||
} else {
|
||||
answer = removeTags(
|
||||
question.structure.options[question.structure.answer].text
|
||||
);
|
||||
}
|
||||
} else if (question.type == "MSQ") {
|
||||
answer = question.structure.answer
|
||||
.map((answerC) => {
|
||||
if (question.structure.options[answerC].text == "") {
|
||||
return question.structure.options[answerC].media[0].url;
|
||||
} else {
|
||||
return removeTags(question.structure.options[answerC].text);
|
||||
}
|
||||
})
|
||||
.filter((a) => a !== undefined);
|
||||
} else if (question.type == "BLANK") {
|
||||
answer = question.structure.options.map((o) => removeTags(o.text));
|
||||
}
|
||||
|
||||
const questionStr = removeTags(question.structure.query.text);
|
||||
|
||||
allAnswers[questionStr] = answer;
|
||||
}
|
||||
|
||||
return allAnswers;
|
||||
}
|
||||
|
||||
function printQuestion(question) {
|
||||
console.log(chalk.italic(chalk.blue(question[0])));
|
||||
console.log(chalk.green(question[1]));
|
||||
}
|
||||
|
||||
async function repl(o) {
|
||||
const answer = await rlp.questionAsync(">");
|
||||
|
||||
if (answer === "all") {
|
||||
for (const question of o) {
|
||||
printQuestion(question);
|
||||
}
|
||||
} else {
|
||||
console.log(chalk.underline(answer));
|
||||
|
||||
for (const question of o) {
|
||||
let ok = true;
|
||||
|
||||
for (let i = 0; i < question[0].length; i++) {
|
||||
if (answer[i] === undefined) break;
|
||||
|
||||
if (question[0][i] !== answer[i]) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
printQuestion(question);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repl(o);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const res = await fetch(`https://quizizz.com/quiz/${id}`);
|
||||
const jsonObject = await res.json();
|
||||
const answers = parseFile(jsonObject);
|
||||
|
||||
const sorted = Object.entries(answers).sort();
|
||||
|
||||
repl(sorted);
|
||||
}
|
||||
|
||||
main();
|
1
javascript/quizizz-hack/package.json
Normal file
1
javascript/quizizz-hack/package.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"dependencies":{"chalk":"^4.1.0","node-fetch":"^2.6.1","readline-promise":"^1.0.4"}}
|
63
javascript/quizizz-hack/pnpm-lock.yaml
Normal file
63
javascript/quizizz-hack/pnpm-lock.yaml
Normal file
|
@ -0,0 +1,63 @@
|
|||
dependencies:
|
||||
chalk: 4.1.0
|
||||
node-fetch: 2.6.1
|
||||
readline-promise: 1.0.4
|
||||
lockfileVersion: 5.1
|
||||
packages:
|
||||
/ansi-styles/4.3.0:
|
||||
dependencies:
|
||||
color-convert: 2.0.1
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=8'
|
||||
resolution:
|
||||
integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
|
||||
/chalk/4.1.0:
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
supports-color: 7.2.0
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=10'
|
||||
resolution:
|
||||
integrity: sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
|
||||
/color-convert/2.0.1:
|
||||
dependencies:
|
||||
color-name: 1.1.4
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=7.0.0'
|
||||
resolution:
|
||||
integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
|
||||
/color-name/1.1.4:
|
||||
dev: false
|
||||
resolution:
|
||||
integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
|
||||
/has-flag/4.0.0:
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=8'
|
||||
resolution:
|
||||
integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
|
||||
/node-fetch/2.6.1:
|
||||
dev: false
|
||||
engines:
|
||||
node: 4.x || >=6.0.0
|
||||
resolution:
|
||||
integrity: sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
/readline-promise/1.0.4:
|
||||
dev: false
|
||||
resolution:
|
||||
integrity: sha512-b6fycDK7CZWpVXbTl8qnW2jovXPduWKpZGyVZbjK/V4A9iiTU4gur+JEkjjgGKLiDZOftkRCT/dxGLG6hR9HyA==
|
||||
/supports-color/7.2.0:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=8'
|
||||
resolution:
|
||||
integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
|
||||
specifiers:
|
||||
chalk: ^4.1.0
|
||||
node-fetch: ^2.6.1
|
||||
readline-promise: ^1.0.4
|
Loading…
Reference in a new issue