diff options
author | Joel Kronqvist <joelkronqvist@proton.me> | 2023-06-21 13:01:57 +0300 |
---|---|---|
committer | Joel Kronqvist <joelkronqvist@proton.me> | 2023-06-21 13:01:57 +0300 |
commit | 529477dc21ec03842ac55a2719b0875133d2aa43 (patch) | |
tree | dc45521555cfd16407f1b712507556014d0cde8d | |
parent | 9760c6242572f6ed17890b84ec3d14fa414b7579 (diff) | |
parent | d10272298acb4d6e07fb5b73dd7af06d653afd7b (diff) | |
download | LYLLRuoka-529477dc21ec03842ac55a2719b0875133d2aa43.tar.gz LYLLRuoka-529477dc21ec03842ac55a2719b0875133d2aa43.zip |
Merge master branches of GitHub repo and server repo
-rw-r--r-- | Functions/dateFuncs.js | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | food.js | 2 | ||||
-rwxr-xr-x | init.sh | 4 | ||||
-rw-r--r-- | server.js | 4 |
5 files changed, 15 insertions, 9 deletions
diff --git a/Functions/dateFuncs.js b/Functions/dateFuncs.js index 1c8a9df..feda2d9 100644 --- a/Functions/dateFuncs.js +++ b/Functions/dateFuncs.js @@ -5,14 +5,14 @@ function stringToDate(s) { } const isBetweenDates = (date, date1, date2) => { - date = approxDate(date); - date1 = approxDate(date1); - date2 = approxDate(date2); + date = floorDate(date); + date1 = floorDate(date1); + date2 = floorDate(date2); return ((date.getTime() >= date1.getTime()) && (date.getTime() <= date2.getTime())); }; -function approxDate(d) +function floorDate(d) { return new Date(`${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`); } @@ -46,7 +46,9 @@ function run_at_monday_mornings(func) { days_to_elapse = 8 - weekday; ms_to_elapse = ms_in_h * ( days_to_elapse * 24/*hours in a day*/ - - hour + 1.5 // removes unneccessary hours so that we update it at 1:30 am + - hour + 1.5 // removes unneccessary hours so that we update it at 1:30 am just + //in case the foods aren't updated instantly to the city's + // servers. ); setTimeout(() => run_at_monday_mornings(func), ms_to_elapse); @@ -134,7 +134,7 @@ If you need to troubleshoot the starting, you can find some logs in /tmp/slogs. # Adding cool data that isn't required for the server to run -## Notifying of unusual food shifts (eg. during exams) +## Notifying of unusual food shifts (eg. during exams or vacations) Currently the notifications have to be added manually to the MySQL database. Here's an example: ``` @@ -4,7 +4,7 @@ const { weekdayToNumber } = require("./Functions/dateFuncs.js"); function* scrapeFood(data) { - const foodRegex = /<title>(\w{2} (?:\d\d?\.){2}\d{4})<\/title><description><!\[CDATA\[(Lounas) ?:? ?(.*?)<br>(Kasvislounas) ?:? ?(.*?)]]><\/description>/gm + const foodRegex = /<title>(\w{2} (?:\d\d?\.){2}\d{4})<\/title><description><!\[CDATA\[(Lounas) ?:? ?(.*?)(Kasvislounas) ?:? ?(.*?)]]><\/description>/gm; const foods = data.matchAll(foodRegex); for(const food of foods) { @@ -26,6 +26,8 @@ while echo "# node server.js:"; do # Sleep below, so that the loop can't cause too big a load to the server, if the server terminates very fast. sleep 5 - echo "# SERVER TERMINATED at $(date)!" + echo "# Server terminated at $(date)" echo "--------" + echo "" + echo "" done @@ -182,7 +182,7 @@ async function buildMain(args) let day = d.getDay(); day = (day + +(day === 0) * 7) - 1; // converts from 0 = sunday to 0 = monday const actualDay = day; - day = +(!(day === 5) && !(day === 6)) * day; + day = +(!(day === 5) && !(day === 6)) * day; // resets day to monday if saturday or sunday 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); // set the day selected (must be done manually with this replacement system) @@ -239,11 +239,13 @@ async function buildMain(args) const examInfo = await SQLDB.query("SELECT * FROM exams"); for(let week = 0; week < examInfo.length; week++) { + // get the date of the requested day const nextDate = new Date( d.getFullYear(), d.getMonth(), d.getDate() + day - actualDay + (day < actualDay)*7 ); + if (dateFuncs.between( nextDate, new Date(examInfo[week].start), |