From c6eb85c138c267db08103de28a3a7c6dffee6c4f Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Wed, 21 Jun 2023 14:18:27 +0300 Subject: Rescued WIP Shift, class and exception updation --- parseClasses.js | 61 +++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'parseClasses.js') diff --git a/parseClasses.js b/parseClasses.js index b114f33..fd48768 100644 --- a/parseClasses.js +++ b/parseClasses.js @@ -5,46 +5,38 @@ const readline = require("readline"); const stream = require("stream"); const getIndexType = require("./dbparse.js").indexType; -// What a mess. -async function parseClassData(path, DB) +async function parseClassData(classes, DB) { const separator = "\t"; - const inStream = fs.createReadStream(path) - const outStream = new stream(); - const rl = readline.createInterface(inStream, outStream); - + classes = classes.split('\n'); let lineNum = 0; let courses = []; - rl.on("line", line => - { + for(let line of classes) { let lineList = line.split(separator); - let type = getIndexType(lineList[0]); - if (!((type === "class") || (type === "teacher"))) - lineNum = 0; + let type = getIndexType(lineList[0]); + if (!((type === "class") || (type === "teacher"))) + lineNum = 0; - if (lineNum % 3 === 0) - courses = lineList; + if (lineNum % 3 === 0) + courses = lineList; if ((lineNum % 3) === 2) - { - // Remove the weird "R":s in the end of the classes - for(let i = 0; i < lineList.length; i++) - { - let _s = lineList[i]; - lineList[i] = _s.substring(0, _s.length - 1); - } + { + // Remove the weird "R":s in the end of the classes + for(let i = 0; i < lineList.length; i++) + { + let _s = lineList[i]; + lineList[i] = _s.substring(0, _s.length - 1); + } addToDBFromLists(DB, courses, lineList, - index => { return getIndexType(index) === "course"; }, - index => { return getIndexType(index) === "class"; } - ); - } + index => { return getIndexType(index) === "course"; }, + index => { return getIndexType(index) === "class"; } + ); + } lineNum++ - }); - rl.on("close", () => - { - return 0; - }); + } + return 0; } function addToDBFromLists(DB, l1, l2, l1cond, l2cond) @@ -56,13 +48,10 @@ function addToDBFromLists(DB, l1, l2, l1cond, l2cond) } } -async function parseClasses(DB, ...paths) +async function parseClasses(DB, classes) { - let parsed = []; - await DB.query_raw("DELETE FROM classes"); - for(const path of paths) - parsed.push(parseClassData(path, DB)) - return await Promise.all(parsed); + await DB.query_raw("DELETE FROM classes"); + return await parseClassData(classes, DB); } -exports.classes = parseClasses; \ No newline at end of file +exports.classes = parseClasses; -- cgit v1.2.3