');
// get the food
let food;
food = foods[ +(day < actualDay) ][day];
if (food !== undefined)
{
res["food-header"] = food[0];
res["food"] = food[1];
}
else
{
res["food-header"] = weekdays[day];
res["food"] = "Päivälle ei löytynyt ruokaa";
}
res["food-header"] = `Päivän ${res["food-header"]} kouluruoka:`;
data_string = build_replace(data_string, res);
return data_string;
}
async function buildDevs(args)
{
const path = args["path"];
const data = await openFile(path);
const DB = args["sqldb"];
let res = "";
let devs = await DB.query_raw("SELECT name, description, contact FROM devs");
for (let dev = 0; dev < devs.length; dev++)
{
let devInfo = devs[dev];
res += '
';
}
return build_replace(data.toString("utf-8"), {"devs": res});
}
async function build404(args)
{
args["path"] = args["path"].substring("./Cont".length);
const data = await openFile(args["path404"]);
const data_string = data.toString("utf-8");
return data_string.replace("\\(path\\)", args["path"]);
}
async function buildDefault(args)
{
const path = args["path"];
const data = await openFile(path);
return data.toString("utf-8");
}
async function buildImage(args)
{
const path = args["path"];
const data = await openFile(path);
return data;
}
function build_replace(s, dict)
{
for (const [key, val] of Object.entries(dict))
{
s = s.replaceAll(`\\(${key}\\)`, val);
}
return s;
}
// Run this if you want to build the database from text files
async function buildDB(SQLDB, shiftfile = "./shifts.txt", classfile = "./classes.txt")
{
let [shiftCont, classCont] = await Promise.all([
openFile(shiftfile),
openFile(classfile)
]);
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 Promise.all([
DBPARSE.classes(classCont, SQLDB),
DBPARSE.build(shiftCont, SQLDB)
]);
return 0;
}
init();