diff --git a/lasvecka-node/calc_date.js b/lasvecka-node/calc_date.js index 20d3b99..e564fad 100644 --- a/lasvecka-node/calc_date.js +++ b/lasvecka-node/calc_date.js @@ -65,6 +65,10 @@ function computeTime() { } let deltaT = currentDate.diff(moment(dat), "days"); + if (typ === 'first_day') { + const weeks = Math.floor(deltaT / 7); + return `MV ${weeks + 1}`; + } if (easterStartCheck >= 0 && easterEndCheck <= 0) { return "Självstudier"; diff --git a/lasvecka-node/data/data.json b/lasvecka-node/data/data.json index ee91b3a..605cfa3 100644 --- a/lasvecka-node/data/data.json +++ b/lasvecka-node/data/data.json @@ -1 +1 @@ -{"2024-09-02":"study_period","2024-10-26":"exam_period","2024-11-04":"study_period","2025-01-11":"exam_period","2025-01-20":"study_period","2025-03-15":"exam_period","2025-03-24":"study_period","easter_start":"2025-04-14","easter_end":"2025-04-16","ord_cont":"2025-04-14","2025-05-31":"exam_period","updated":"2024-09-02"} \ No newline at end of file +{"2024-09-02":"study_period","2024-08-20":"first_day","2024-10-26":"exam_period","2024-11-04":"study_period","2025-01-11":"exam_period","2025-01-20":"study_period","2025-03-15":"exam_period","2025-03-24":"study_period","easter_start":"2025-04-14","easter_end":"2025-04-16","ord_cont":"2025-04-14","2025-05-31":"exam_period","updated":"2024-09-02"} \ No newline at end of file diff --git a/lasvecka-node/index.js b/lasvecka-node/index.js index 3fdaa1e..493c1bf 100644 --- a/lasvecka-node/index.js +++ b/lasvecka-node/index.js @@ -11,6 +11,7 @@ function updateStudyWeek() { studyweek = computeTime(); studyweekNum = studyweek .replace("LV ", "") + .replace("MV ", "") .replace("Självstudier", "S") .replace("Tentavecka", "T"); return { studyweek, studyweekNum }; @@ -33,8 +34,10 @@ app.get("/favicon.ico", (req, res) => { const studyweek = computeTime(); const studyweekNum = studyweek .replace("LV ", "") + .replace("MV ", "") .replace("Självstudier", "S") .replace("Tentavecka", "T"); + console.log(studyweekNum); res.sendFile(`${__dirname}/public/icons/${studyweekNum}/favicon.ico`); }); @@ -42,6 +45,7 @@ app.get("/site.webmanifest", (req, res) => { const studyweek = computeTime(); const studyweekNum = studyweek .replace("LV ", "") + .replace("MV ", "") .replace("Självstudier", "S") .replace("Tentavecka", "T"); const manifest = { diff --git a/lasvecka-node/lasveckor_scraper.js b/lasvecka-node/lasveckor_scraper.js index 3befa0a..3d63e76 100644 --- a/lasvecka-node/lasveckor_scraper.js +++ b/lasvecka-node/lasveckor_scraper.js @@ -1,5 +1,6 @@ const fs = require("node:fs"); const axios = require("axios"); +const moment = require("moment"); async function scrape() { console.log("Scraping data from student.chalmers.se"); @@ -27,6 +28,10 @@ async function scrape() { if (line.startsWith("Läsperiod")) { const date = line.match(/(\d{4}-\d{2}-\d{2})/)[0]; result[date] = "study_period"; + if (line.startsWith("Läsperiod 1")) { + const firstDayDate = moment(date).subtract(13, "days").format('YYYY-MM-DD'); + result[firstDayDate] = "first_day"; + } } else if (line.startsWith("Tentamensperiod")) { const date = line.match(/(\d{4}-\d{2}-\d{2})/)[0]; result[date] = "exam_period";