From 24709fa862636702fd0430e832463b751fce323e Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Sat, 8 Jan 2022 16:49:37 +0200 Subject: Parsing the shifts (not classes) to the database + some GUI improvements --- Cont/404/index.css | 3 + Cont/404/index.html | 26 ++++++++ Cont/Images/back.png | Bin 0 -> 3528 bytes Cont/Images/help.png | Bin 0 -> 2347 bytes Cont/devs/index.css | 18 ++++++ Cont/devs/index.html | 26 ++++++++ Cont/index.css | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cont/index.html | 63 +++++++++++++++++++ Cont/non-main.css | 26 ++++++++ 9 files changed, 337 insertions(+) create mode 100644 Cont/404/index.css create mode 100644 Cont/404/index.html create mode 100644 Cont/Images/back.png create mode 100644 Cont/Images/help.png create mode 100644 Cont/devs/index.css create mode 100644 Cont/devs/index.html create mode 100644 Cont/index.css create mode 100644 Cont/index.html create mode 100644 Cont/non-main.css (limited to 'Cont') diff --git a/Cont/404/index.css b/Cont/404/index.css new file mode 100644 index 0000000..664d7fb --- /dev/null +++ b/Cont/404/index.css @@ -0,0 +1,3 @@ +body { + padding-top: 30vh; +} diff --git a/Cont/404/index.html b/Cont/404/index.html new file mode 100644 index 0000000..5b01684 --- /dev/null +++ b/Cont/404/index.html @@ -0,0 +1,26 @@ + + + + + Page not found + + + + + + +
+

404: sivua \(path\) ei löytynyt.

+

Voi myös olla, että palvelimella on tapahtunut virhe. Jos epäilet jälkimmäistä, otathan yhteyttä palvelusta vastaaviin henkilöihin.

+
+ + Takaisin etusivulle + + + + + diff --git a/Cont/Images/back.png b/Cont/Images/back.png new file mode 100644 index 0000000..01b9bc7 Binary files /dev/null and b/Cont/Images/back.png differ diff --git a/Cont/Images/help.png b/Cont/Images/help.png new file mode 100644 index 0000000..51d84df Binary files /dev/null and b/Cont/Images/help.png differ diff --git a/Cont/devs/index.css b/Cont/devs/index.css new file mode 100644 index 0000000..1cce621 --- /dev/null +++ b/Cont/devs/index.css @@ -0,0 +1,18 @@ +.column { + display: inline-block; + padding: 0; + margin: .5em; + box-sizing: border-box; + vertical-align: middle; + overflow-wrap: break-word; + width: 100%; +} + + +@media screen and (min-width: 700px) +{ + .column { + width: calc(33% - 2em); + } +} + diff --git a/Cont/devs/index.html b/Cont/devs/index.html new file mode 100644 index 0000000..69116c6 --- /dev/null +++ b/Cont/devs/index.html @@ -0,0 +1,26 @@ + + + + + Developers + + + + + + +

Sivun kehittäjät

+

Jos muokkaat/lisäät jotain tähän projektiin, voit pyytää serverin ylläpidosta vastaavilta, että nimesi lisätään tietokantaan.

+ + \(devs\) + + Takaisin etusivulle + + + + + diff --git a/Cont/index.css b/Cont/index.css new file mode 100644 index 0000000..1f5a422 --- /dev/null +++ b/Cont/index.css @@ -0,0 +1,175 @@ +* { + margin: 0; + padding: 0; + text-align: center; + --info-width: 13em; + --fadetime: .3s; + --box-bg: #222; + --box-shadow: black; +} + +/*** bg etc... ***/ +body { + background: #444; + color: white; + padding: 1em; + margin-bottom: 3em; /* for the footer */ + + font-family: verdana, sans-serif; +} + +.shadow { + text-shadow: .124em .125em black; +} + +/*** dual layout ***/ +#foodshift, #food { + width: 100%; + box-sizing: border-box; + display: inline-block; + vertical-align: top; +} + +/*** responsivity ***/ +@media screen and (min-width: 700px) +{ + #foodshift + { + width: 58%; + } + #food { + width: 41%; + } +} + +/*** the ui blocks ***/ +.float-block { + display: inline-block; + margin: 1em; + padding: 1em; + + background: var(--box-bg); + border: 0 solid black; + border-radius: 5px; +} + +.float-block p, .float-block h1, .float-block h2, .float-block label, .float-block select, .float-block input { + margin: .5em; +} + +/*** the input field & choose ***/ +#input[type="text"], select { + background-color: white; +} + +/*** the send-button ***/ +#send { + background: blue; + padding: .5em; + margin: .5em; + font-weight: bold; + + position: relative; + right: .125em; + bottom: .125em; +} + +#send:hover { + right: .25em; + bottom: .25em; + box-shadow: .25em .25em; +} + +/*** Footer ***/ +footer { + position: fixed; + top: calc(100% - 3em); + left: 0; + + width: 100%; + margin: 0; + padding: 1em; + line-height: 1em; + box-sizing: border-box; + + background-color: #0d0d0d; +} + +footer > a { + color: #b3b3b3; +} + +/*** The shadowed elements ***/ +.highlight { + border: 1px solid black; + border-radius: 5px; + box-shadow: .125em .125em var(--box-shadow); +} + +/*** the info buttons & their animations ***/ +img.info { + width: 1em; + height: 1em; + vertical-align: middle; +} + +img.info + span { + position: relative; + vertical-align: middle; + left: -1em; + animation: hide-at-start calc(var(--fadetime) * 1.1); /* this hides the flash of the child element in the start */ +} +@keyframes hide-at-start { + 0% { bottom: 200vh; } + 99%{ bottom: 200vh; } + 100%{ bottom: 0; } +} + +p.infoblock { + display: inline; + position: absolute; + top: 1.5em; + left: calc(var(--info-width) * -1 - 1em); + width: var(--info-width); + z-index: 1; + + background-color: var(--box-bg); + --box-shadow: #111; + margin: 0; + padding: .5em; + border-radius: 5px 0 5px 5px; + + animation-name: fade-out; + animation-duration: var(--fadetime); + visibility: hidden; + opacity: 0; +} + +img.info:hover + span > p.infoblock { + animation-name: fade-in; + animation-duration: var(--fadetime); + visibility: visible; + opacity: 1; +} + +@keyframes fade-in { + 0% { + visibility: hidden; + opacity: 0; + } + 100% { + opacity: 1; + visibility: visible; + } +} + +@keyframes fade-out { + 0% { + opacity: 1; + visibility: visible; + } + 100% { + opacity: 0; + visibility: hidden; + } +} diff --git a/Cont/index.html b/Cont/index.html new file mode 100644 index 0000000..c35b7c1 --- /dev/null +++ b/Cont/index.html @@ -0,0 +1,63 @@ + + + + + LYLL-ruokailuvuoro + + + + +
+

LYLL-ruoka

+
+ +
+ +
+
+
+ +
+ + Siis häh? +

Syötä tähän kenttään yhdeltätoista alkavan tuntisi opettaja, kurssikoodi tai luokka. Älä syötä useampaa edellä mainituista, yksi on tarpeeksi.

+
+ +
+ +
+ +
+ +
+ +
+

\(index-type\) \(shift-header\) ruokailuvuoro \(day\):

+

\(shift\)

+
+
+ + +
+
+

\(food-header\)

+

\(food\)

+
+
+
+ + + + diff --git a/Cont/non-main.css b/Cont/non-main.css new file mode 100644 index 0000000..d8003ef --- /dev/null +++ b/Cont/non-main.css @@ -0,0 +1,26 @@ +.back { + display: block; + margin-left: auto; + margin-right: auto; +} + +.back > * { +} + +.back > img { + width: 4rem; + height: 4rem; + margin: 1rem; + filter: drop-shadow(.125rem .125rem 0 black); + position: relative; + bottom: .125rem; + right: .125rem; + vertical-align: middle; + display: inline; +} + +.back > img:hover { + filter: drop-shadow(.20rem .20rem 0 black); + bottom: .20rem; + right: .20rem; +} -- cgit v1.3.1 From 21e79dcc1eabebfd661a2fd38681348ae9428c4e Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Sun, 9 Jan 2022 20:17:16 +0200 Subject: Database implemented Some polishing wouldn't do bad though... --- Cont/index.css | 6 ++ Cont/index.html | 14 +-- dbparse.js | 175 ++++++++----------------------------- parse.js | 265 -------------------------------------------------------- scrape.js | 7 +- server.js | 74 +++++++++------- 6 files changed, 96 insertions(+), 445 deletions(-) delete mode 100644 parse.js (limited to 'Cont') diff --git a/Cont/index.css b/Cont/index.css index 1f5a422..80e5dc6 100644 --- a/Cont/index.css +++ b/Cont/index.css @@ -107,10 +107,16 @@ footer > a { } /*** the info buttons & their animations ***/ +img.info:hover { + filter: drop-shadow(.125rem .125rem 0 black); + transform: translate(-0.125rem, -0.125rem); +} img.info { width: 1em; height: 1em; vertical-align: middle; + filter: drop-shadow(.0625rem .0625rem 0 black); + transform: translate(-0.0625rem, -0.0625rem); } img.info + span { diff --git a/Cont/index.html b/Cont/index.html index c35b7c1..95dcb32 100644 --- a/Cont/index.html +++ b/Cont/index.html @@ -25,13 +25,13 @@

diff --git a/dbparse.js b/dbparse.js index b260d50..ec2d434 100644 --- a/dbparse.js +++ b/dbparse.js @@ -84,98 +84,7 @@ async function writeClasses(classData, DB) let res = await DB.execute("INSERT INTO classes VALUES (?, ?)", [key, val]); } } -/* -function parseShift(data, weekdays = ["MAANANTAISIN", "TIISTAISIN", "KESKIVIIKKOISIN", "TORSTAISIN", "PERJANTAISIN"]) -{ - - let i = 0; - let db = []; - while (db.length < weekdays.length) - { - let day = []; - - i = getNextChar(data, "\n", findExpression(data, weekdays[db.length])); - let end; - if (db.length === weekdays.length - 1) - end = data.length; - else - end = findExpression(data, weekdays[db.length + 1]); - let unparsedDay = data.substring(i + 1, end); - day = parseDay(unparsedDay); - - db.push(day); - } - return db; -} - -function parseDay(day) -{ - let shifts = {}; - let i = getToLineStartingWith(day, "RUOKAILUVUORO"); - do - { - let endOfLine = getNextChar(day, "\n", i); - let shiftDesc = day.substring(i, endOfLine); - i = getNextChar(day, "\n", i) + 1; - i = getNextChar(day, "\n", i) + 1; - if (getNextChar(day, "\n", i) === -1) - endOfLine = day.length; - else - endOfLine = getNextChar(day, "\n", i); - let unparsedIndexes = day.substring(i, endOfLine); - shifts[shiftDesc] = parseLine(unparsedIndexes); - i = getToLineStartingWith(day, "RUOKAILUVUORO", i); - } while (i !== -1); - return shifts; -} -function parseLine(line, toRemove = " ja KAHDEN TUTKINNON OPINNOT 1., 2. ja 3. VUOSITASON RYHMÄT ") -{ - let i = 0; - let courses = []; - let teachers = []; - // get to the teachers & courses - let nextSpace = 0; - - if (line.substring(line.length - toRemove.length, line.length) === toRemove) - line = line.substring(0, line.length - toRemove.length); - line = line.replaceAll(",", "").replaceAll("ja ", "").replaceAll(" + ", "+"); - - while (i < line.length) - { - if (line[i] === "+") - { - - nextSpace = getNextChar(line, " ", i); - let nextNextSpace = getNextChar(line, " ", nextSpace + 1); - if (nextNextSpace === -1) - nextNextSpace = line.length; - line = `${line.substring(0, i)} ${line.substring(nextSpace + 1, nextNextSpace)} ${line.substring(i + 1, line.length)}`; - i = nextNextSpace - 1; - } - i++; - } - nextSpace = 0; - i = 0; - - const getElement = list => - { - nextSpace = getNextChar(line, " ", i); - if (nextSpace === -1) - nextSpace = line.length; - list.push(line.substring(i, nextSpace)); - i = nextSpace + 1; - } - do - { - getElement(courses); - getElement(teachers); - } while (i < line.length) - - return [courses, teachers]; -} - -*/ async function parseLine(data, day, shift, DB) { // "preprocessing" @@ -285,10 +194,31 @@ async function writeShifts(data, DB) i = end; } + + const courses = await DB.query_raw("SELECT * FROM classes"); + const results = []; + for (let course = 0; course < courses.length; course++) + { + results.push(DB.query("UPDATE shifts SET class = ? WHERE course = ?", [courses[course].class, courses[course].course])); + } + await Promise.all(results); return 0; } -/* +async function getShift(day, index, DB) +{ + let shift = DB.execute("SELECT name FROM shiftnames WHERE day = ? and id = (SELECT shift FROM shifts WHERE (day = ?) AND (course = ? OR teacher = ? OR class = ?) LIMIT 1)", [day, day, index, index, index]); + let additional = DB.execute("SELECT course, teacher, class FROM shifts WHERE (day = ?) AND (course = ? OR teacher = ? OR class = ?)", [day, index, index, index]); + [shift, additional] = await Promise.all([shift, additional]); + if (shift.length !== 0) + { + shift.push(additional); + return shift; + } + return undefined; +} + + function getIndexType(index) { if (/^[A-Za-zåäöÅÄÖ]{2,3}\d{2,3}$/.test(index)) @@ -299,67 +229,32 @@ function getIndexType(index) return "class"; } -function getShift(day, index, db) // day: int, 1 = monday; index: string of course/teacher; db: parsed shifts -{ - if ((typeof day !== "number") || isNaN(day) || (typeof index !== "string")) - return -1; - - let shifts = db[day - 1]; - - let _endOfIndex = parseInt(index.substring(2, 4)); - let type = getIndexType(index); - if (type === undefined) - return {}; - let type_index = +(type === "teacher") + (+(type === "class") * 2); - - let res = {}; - for (const [key, val] of Object.entries(shifts)) - { - let indexes = val[type_index]; - for (let i = 0; i < indexes.length; i++) - { - if (indexes[i] === index) - res[key] = [val[0][i], val[1][i], val[2][i]]; - } - } - return res; -} - function randInt(start, stop) { return start + Math.floor(Math.random() * (stop - start)); } -function getIndexes(db, day, shift, type) -{ - let d = db[day]; - let sh = Object.values(d)[shift][type]; - return Object.values(db[day])[shift][type]; -} - -function getRandomIndex(db, day = randInt(0, 5), shift = randInt(0, 3), type = randInt(0, 3)) +async function getRandomIndex(day, DB) { - let el; - let i = 0; - let indexes = getIndexes(db, day, shift, type); - while ((el === undefined) && (i < indexes.length)) + let indexes = await DB.execute("SELECT course, teacher, class FROM shifts WHERE day = ? ORDER BY RAND() LIMIT 1", [day]); + indexes = Object.values(indexes[0]); + let start = randInt(0, indexes.length); + for (let test = 0; test < 3; test++) { - el = indexes[i]; - i++; + let i = (start + test) % indexes.length; + if (indexes[i] !== null) + return indexes[i]; } - if (el == undefined) - return getRandomIndex(db); - return el; + console.log("Warning: row without class/teacher/course in database!"); + return getRandomIndex(day, DB); } -exports.build = parseShift; + exports.indexType = getIndexType; -exports.classes = parseClasses; -exports.get = getShift; exports.cluttered = parseCluttered; exports.find = findExpression; exports.getNextChar = getNextChar; -exports.randomIndex = getRandomIndex;*/ - exports.classes = writeClasses; exports.build = writeShifts; +exports.get = getShift; +exports.randomIndex = getRandomIndex; diff --git a/parse.js b/parse.js deleted file mode 100644 index a776f13..0000000 --- a/parse.js +++ /dev/null @@ -1,265 +0,0 @@ -function getCharAmount(s, c) -{ - let n = 0; - for (let c_i = 0; c_i < s.length; c_i++) - { - n += +(s[c_i] === c); - } - return n; -} - -function getNextChar(s, c, i = 0) -{ - if (!(Number.isInteger(i) && (i >= 0))) - return -1; - for (; i < s.length; i++) - { - if (s[i] === c) - return i; - } - return -1; -} -function getNextLine(s, i) -{ - i = getNextChar(s, "\n", i); - i += +(i !== -1) * 1; - return i; -} -function getToLineStartingWith(s, ss, start = 0) -{ - if (!(Number.isInteger(start) && (start >= 0))) - return -1 - - let i = start; - do - { - if (s.substring(i, i + ss.length) === ss) - break; - i = getNextLine(s, i); - } while(i !== -1) - - return i; -} - -function findExpression(data, expr, start = 0) -{ - if (start == -1) - return -1; - if (!(Number.isInteger(start) && (start >= 0))) - throw new TypeError("Start must be a positive integer!"); - while ((data.substring(start, start + expr.length) !== expr) && (start + expr.length < data.length)) - start++; - if (data.substring(start, start + expr.length) !== expr) - return -1; - return start; -} - -function parseCluttered(s) -{ - if (!(typeof s === "string")) - return ""; - return s.replaceAll(".", "").replaceAll(" ", "").toUpperCase(); -} - -function parseClasses(classData, DB) -{ - classData = parseCluttered(classData) + "\n"; // newline so that loop can find last value - // parse data to dict - let classes = {}; - let i = 0; - while (i < classData.length) - { - let separator = getNextChar(classData, ":", i); - let lineEnd = getNextChar(classData, "\n", i); - let key = classData.substring(i, separator); - let val = classData.substring(separator + 1, lineEnd); - i = lineEnd + 1; - classes[key] = val; - } - - for (let day = 0; day < DB.length; day++) - { - let shifts = DB[day]; - for (const [key, val] of Object.entries(shifts)) - { - DB[day][key].push([]); - let indexes = val[0]; // use courses: the classes are paired to them and they are unique with a higher probability - for (let i = 0; i < indexes.length; i++) - { - DB[day][key][2].push(classes[indexes[i]]); - } - } - } - -} - -function parseLine(line, toRemove = " ja KAHDEN TUTKINNON OPINNOT 1., 2. ja 3. VUOSITASON RYHMÄT ") -{ - let i = 0; - let courses = []; - let teachers = []; - let nextSpace = 0; - - if (line.substring(line.length - toRemove.length, line.length) === toRemove) - line = line.substring(0, line.length - toRemove.length); - line = line.replaceAll(",", "").replaceAll("ja ", "").replaceAll(" + ", "+"); - - while (i < line.length) - { - if (line[i] === "+") - { - - nextSpace = getNextChar(line, " ", i); - let nextNextSpace = getNextChar(line, " ", nextSpace + 1); - if (nextNextSpace === -1) - nextNextSpace = line.length; - line = `${line.substring(0, i)} ${line.substring(nextSpace + 1, nextNextSpace)} ${line.substring(i + 1, line.length)}`; - i = nextNextSpace - 1; - } - i++; - } - nextSpace = 0; - i = 0; - - const getElement = list => - { - nextSpace = getNextChar(line, " ", i); - if (nextSpace === -1) - nextSpace = line.length; - list.push(line.substring(i, nextSpace)); - i = nextSpace + 1; - } - - do - { - getElement(courses); - getElement(teachers); - } while (i < line.length) - - return [courses, teachers]; -} - -function parseDay(day) -{ - let shifts = {}; - let i = getToLineStartingWith(day, "RUOKAILUVUORO"); - do - { - let endOfLine = getNextChar(day, "\n", i); - let shiftDesc = day.substring(i, endOfLine); - i = getNextChar(day, "\n", i) + 1; - i = getNextChar(day, "\n", i) + 1; - if (getNextChar(day, "\n", i) === -1) - endOfLine = day.length; - else - endOfLine = getNextChar(day, "\n", i); - let unparsedIndexes = day.substring(i, endOfLine); - shifts[shiftDesc] = parseLine(unparsedIndexes); - i = getToLineStartingWith(day, "RUOKAILUVUORO", i); - } while (i !== -1); - return shifts; -} - -function parseShift(data, weekdays = ["MAANANTAISIN", "TIISTAISIN", "KESKIVIIKKOISIN", "TORSTAISIN", "PERJANTAISIN"]) -{ - - let i = 0; - let db = []; - while (db.length < weekdays.length) - { - let day = []; - - i = getNextChar(data, "\n", findExpression(data, weekdays[db.length])); - let end; - if (db.length === weekdays.length - 1) - end = data.length; - else - end = findExpression(data, weekdays[db.length + 1]); - let unparsedDay = data.substring(i + 1, end); - day = parseDay(unparsedDay); - - db.push(day); - } - return db; -} - -/* - * DB structure: - * WEEKDAY - list - * FOOD SHIFTS - dict - * COURSE INDEXES - list - * TEACHER INDEXES - list - * maybe: CLASSES - list - */ - -function getIndexType(index) -{ - if (/^[A-Za-zåäöÅÄÖ]{2,3}\d{2,3}$/.test(index)) - return "course"; - if (/^[A-Za-zåäöÅÄÖ]{4}$/.test(index)) - return "teacher"; - if (/^\w\d{3}$/.test(index)) - return "class"; -} - -function getShift(day, index, db) // day: int, 1 = monday; index: string of course/teacher; db: parsed shifts -{ - if ((typeof day !== "number") || isNaN(day) || (typeof index !== "string")) - return -1; - - let shifts = db[day - 1]; - - let _endOfIndex = parseInt(index.substring(2, 4)); - let type = getIndexType(index); - if (type === undefined) - return {}; - let type_index = +(type === "teacher") + (+(type === "class") * 2); - - let res = {}; - for (const [key, val] of Object.entries(shifts)) - { - let indexes = val[type_index]; - for (let i = 0; i < indexes.length; i++) - { - if (indexes[i] === index) - res[key] = [val[0][i], val[1][i], val[2][i]]; - } - } - return res; -} - -function randInt(start, stop) -{ - return start + Math.floor(Math.random() * (stop - start)); -} - -function getIndexes(db, day, shift, type) -{ - let d = db[day]; - let sh = Object.values(d)[shift][type]; - return Object.values(db[day])[shift][type]; -} - -function getRandomIndex(db, day = randInt(0, 5), shift = randInt(0, 3), type = randInt(0, 3)) -{ - let el; - let i = 0; - let indexes = getIndexes(db, day, shift, type); - while ((el === undefined) && (i < indexes.length)) - { - el = indexes[i]; - i++; - } - if (el == undefined) - return getRandomIndex(db); - return el; -} - -exports.build = parseShift; -exports.indexType = getIndexType; -exports.classes = parseClasses; -exports.get = getShift; -exports.cluttered = parseCluttered; -exports.find = findExpression; -exports.getNextChar = getNextChar; -exports.randomIndex = getRandomIndex; diff --git a/scrape.js b/scrape.js index 64e00fb..0ae30aa 100644 --- a/scrape.js +++ b/scrape.js @@ -1,4 +1,7 @@ -const https = require("https"); const parse = require("./parse.js"); const fs = require("fs"); const events = require("events"); +const https = require("https"); +const parse = require("./DBPARSE.js"); +const fs = require("fs"); +const events = require("events"); async function urlOpen(path) { @@ -22,7 +25,7 @@ async function scrapeFood(url) data = data.toString("utf-8"); let foodList = []; - const weekdays = ["su", "ma", "ti", "ke", "to", "pe", "la"]; + const weekdays = ["ma", "ti", "ke", "to", "pe", "la", "su"]; let titleTags = ["", ""]; let foodTags = [""]; diff --git a/server.js b/server.js index 26ab9bb..d92a8eb 100644 --- a/server.js +++ b/server.js @@ -1,7 +1,6 @@ const http = require("http"); const fs = require("fs"); const url = require("url"); -const parse = require("./parse.js"); const scrape = require("./scrape.js"); const SQL_DBS = require("./database.js"); const DBPARSE = require("./dbparse.js"); @@ -23,10 +22,11 @@ async function init() }; const errorPath = "./Cont/404/index.html"; + + + // await for needed things in async - let [shiftCont, classCont, foodsThisWeek, foodsNextWeek, dbcredentials] = await Promise.all([ - openFile("./shifts.txt"), - openFile("./classes.txt"), + let [foodsThisWeek, foodsNextWeek, dbcredentials] = await Promise.all([ scrape.food(scrape.link(1)), scrape.food(scrape.link(2)), openFile("../dblogin.txt") @@ -35,16 +35,6 @@ async function init() // get the MySQL DB connection const SQLDB = new SQL_DBS.Database(JSON.parse(dbcredentials)); - // get the food shift "database" - shiftCont = shiftCont.toString("utf-8").replaceAll("\r", ""); // \r because of the \r\n newline on windows which creates problems - classCont = classCont.toString("utf-8").replaceAll("\r", ""); - - await DBPARSE.classes(classCont, SQLDB); - await DBPARSE.build(shiftCont, SQLDB); - - let DB = parse.build(shiftCont); - parse.classes(classCont, DB); - // get the food "database" const foods = [foodsThisWeek, foodsNextWeek]; @@ -77,7 +67,6 @@ async function init() "path": path, "path404": errorPath, "query": q.query, - "db": DB, "foods": foods, "sqldb": SQLDB }; @@ -108,7 +97,7 @@ async function init() function validateIndex(sus) { - return antiXSS(parse.cluttered(sus)); + return antiXSS(DBPARSE.cluttered(sus)); } function antiXSS(sus) @@ -120,7 +109,7 @@ function antiXSS(sus) function isDir(path) { - return (parse.getNextChar(path.substring(1), ".") === -1); + return (DBPARSE.getNextChar(path.substring(1), ".") === -1); } @@ -152,7 +141,7 @@ async function buildMain(args) const query = args["query"]; const foods = args["foods"]; const index = query.index; - const DB = args["db"]; + const SQLDB = args["sqldb"]; const data = await openFile(path); let data_string = data.toString("utf-8"); @@ -160,9 +149,10 @@ async function buildMain(args) const d = new Date(); let day = d.getDay(); + day = (day + +(day === 0) * 7) - 1; const actualDay = day; - day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); - if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 6)) + day = +(!(day === 5) && !(day === 6)) * day; + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) >= 0) && (parseInt(query.day) < 5)) day = parseInt(query.day); data_string = data_string.replace(`