bad_schlüko_parser
This commit is contained in:
parent
d44b1e9aa0
commit
ab22b2e938
1 changed files with 32 additions and 0 deletions
32
js/bad_schlüko_parser.js
Normal file
32
js/bad_schlüko_parser.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
var fs = require("fs");
|
||||
|
||||
let file = fs.readFileSync("../Test.md").toString().split("\n");
|
||||
|
||||
var list = [];
|
||||
let last = null;
|
||||
|
||||
const format = s => s.replace(/(["„“”]([^"„“”]*)["„“”])/g, "„$2“");
|
||||
|
||||
for (let i = 0; i < file.length; i++) {
|
||||
const line = file[i];
|
||||
if (line.trim() == "") continue;
|
||||
if (!isNaN(Number(line[0]))) {
|
||||
if (last != null) list.push(last);
|
||||
last = {
|
||||
quest: format(line.split(" ").slice(1).join(" ")),
|
||||
answers: [],
|
||||
correct: -1,
|
||||
explanation: null
|
||||
};
|
||||
}
|
||||
if (line[0] == "A") last.answers[0] = format(line.substring(3));
|
||||
if (line[0] == "B") last.answers[1] = format(line.substring(3));
|
||||
if (line[0] == "C") last.answers[2] = format(line.substring(3));
|
||||
if (line[0] == "D") last.answers[3] = format(line.substring(3));
|
||||
if (line.startsWith("-> ")) {
|
||||
last.correct = "ABCD".indexOf(line.substring(3, 4));
|
||||
last.explanation = format(line.substring(6));
|
||||
}
|
||||
}
|
||||
//console.log(list);
|
||||
fs.writeFileSync("../Test.json", JSON.stringify({ "name": "schlüko", "questions": list }, null, 2));
|
Loading…
Reference in a new issue