From ab22b2e938d891edd062f0b7d126d03f33e6f91f Mon Sep 17 00:00:00 2001 From: jusax23 Date: Thu, 1 Jun 2023 16:12:08 +0200 Subject: [PATCH] =?UTF-8?q?bad=5Fschl=C3=BCko=5Fparser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/bad_schlüko_parser.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 js/bad_schlüko_parser.js diff --git a/js/bad_schlüko_parser.js b/js/bad_schlüko_parser.js new file mode 100644 index 0000000..ff38d76 --- /dev/null +++ b/js/bad_schlüko_parser.js @@ -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)); \ No newline at end of file