aboutsummaryrefslogtreecommitdiff
path: root/parseClasses.js
diff options
context:
space:
mode:
authorJoel Kronqvist <joelkronqvist@proton.me>2023-06-21 14:18:27 +0300
committerJoel Kronqvist <joelkronqvist@proton.me>2023-06-21 14:18:27 +0300
commitc6eb85c138c267db08103de28a3a7c6dffee6c4f (patch)
tree5c55ba312926d61a13b04b32c9b801120b92fe78 /parseClasses.js
parent529477dc21ec03842ac55a2719b0875133d2aa43 (diff)
downloadLYLLRuoka-c6eb85c138c267db08103de28a3a7c6dffee6c4f.tar.gz
LYLLRuoka-c6eb85c138c267db08103de28a3a7c6dffee6c4f.zip
Rescued WIP Shift, class and exception updation
Diffstat (limited to 'parseClasses.js')
-rw-r--r--parseClasses.js61
1 files changed, 25 insertions, 36 deletions
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;