Skip to content

Commit

Permalink
support reception week 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Sep 2, 2024
1 parent bcaaaee commit 23984ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lasvecka-node/calc_date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lasvecka-node/data/data.json
Original file line number Diff line number Diff line change
@@ -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"}
{"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"}
4 changes: 4 additions & 0 deletions lasvecka-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function updateStudyWeek() {
studyweek = computeTime();
studyweekNum = studyweek
.replace("LV ", "")
.replace("MV ", "")
.replace("Självstudier", "S")
.replace("Tentavecka", "T");
return { studyweek, studyweekNum };
Expand All @@ -33,15 +34,18 @@ 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`);
});

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 = {
Expand Down
5 changes: 5 additions & 0 deletions lasvecka-node/lasveckor_scraper.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 23984ff

Please sign in to comment.