diff options
author | Joel Kronqvist <work.joelkronqvist@pm.me> | 2022-03-10 10:40:10 +0200 |
---|---|---|
committer | Joel Kronqvist <work.joelkronqvist@pm.me> | 2022-03-10 10:40:10 +0200 |
commit | 01f3f5f2ab89432a253c24f76227b8f6855d8446 (patch) | |
tree | 94ae04efb6b93a328ba43f14847f2fd3f3d6d07c | |
parent | fd329fac83ca83b768dbb39a17ea789cc8cdb65b (diff) | |
download | LYLLRuoka-01f3f5f2ab89432a253c24f76227b8f6855d8446.tar.gz LYLLRuoka-01f3f5f2ab89432a253c24f76227b8f6855d8446.zip |
Class parsing with any number of files with classes
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | parseClasses.js | 7 | ||||
-rw-r--r-- | update.js | 11 |
3 files changed, 14 insertions, 14 deletions
@@ -103,20 +103,20 @@ Lets assume the following filesystem that contains also all of the server code: ``` shifts.txt Classes -| oldclasses.txt -| newclasses.txt +| classes.txt ``` -Where shifts.txt contains the shifts, `oldclasses.txt` contains the classes of the old curriculum and `newclasses` the classes of the new learning curriculum. +Where shifts.txt contains the shifts and `classes.txt` contains the classes. -You can get the shifts from junu's food shift message through Wilma. The classes should be tab delimited text files. You can get them easily by copy-pasting them from the eg. LibreOffice from "Kurssitarjottimet". Provide only the classes of one period, not all of them. +You can get the shifts from junu's food shift message through Wilma. The `classes` should be a tab delimited text file. You can get it easily by copy-pasting its contents from eg. LibreOffice from "Kurssitarjottimet". Provide only the classes of one period, not all of them. You can give several class files, if needed. Then just run the following code in node.js: ``` const updateDB = require("./update.js"); const openFile = require("./Functions/open.js").file; const dbcredentials = await openFile("../dblogin.txt"); -await updateDB.update("./shifts.txt", ["./Classes/oldclasses.txt", "./Classes/newclasses.txt"], dbcredentials); +await updateDB.update(dbcredentials, "./shifts.txt", "./Classes/classes.txt"); ``` +If you have several files with classes, just append them to the parameters of `updateDB.update`. ## Updating the developer table Updating the developer table is pretty straightforward. You just need to provide the name of the developer, a description (eg. "Improved the performance of the server") and contact information: diff --git a/parseClasses.js b/parseClasses.js index ffd8e7f..b114f33 100644 --- a/parseClasses.js +++ b/parseClasses.js @@ -56,13 +56,12 @@ function addToDBFromLists(DB, l1, l2, l1cond, l2cond) } } -async function parseClasses(path1, path2, DB) +async function parseClasses(DB, ...paths) { let parsed = []; await DB.query_raw("DELETE FROM classes"); - parsed.push(parseClassData(path1, DB)); - if (path2 !== undefined) - parsed.push(parseClassData(path2, DB)); + for(const path of paths) + parsed.push(parseClassData(path, DB)) return await Promise.all(parsed); } @@ -4,13 +4,14 @@ const parseClasses = require("./parseClasses.js").classes; const parse = require("./dbparse.js"); // Run this if you want to build the database from text files -async function buildDB(shiftfile = "./shifts.txt", classfile = "./classes.txt", dbcredentials) +async function buildDB(dbcredentials, shiftPath, ...classfiles) { - let shiftCont = await openFile(shiftfile); + let shiftCont = await openFile(shiftPath); const DB = new database.Database(JSON.parse(dbcredentials)); shiftCont = shiftCont.toString("utf-8").replaceAll("\r", ""); // \r because of the \r\n newline on windows which creates problems + await Promise.all([ - parseClasses(classfile[0], classfile[1], DB), + parseClasses(DB, ...classfiles), parse.build(shiftCont, DB) ]); return 0; @@ -20,6 +21,6 @@ exports.update = buildDB; // Example call: /* const openFile = require("./Functions/open.js").file; -const dbcredentials = openFile("../dblogin.txt"); -await updateDB.update("./shifts.txt", ["./Kurssitarjottimet/2016Classes.txt", "./Kurssitarjottimet/NewClasses.txt"], dbcredentials); +const dbcredentials = await openFile("../dblogin.txt"); +await updateDB.update(dbcredentials, "./shifts.txt", "./Kurssitarjottimet/2016Classes.txt", "./Kurssitarjottimet/NewClasses.txt"); */
\ No newline at end of file |