✨ Only use substitutions of first day in file
This commit is contained in:
@ -15,36 +15,58 @@ export function parseSubstitutionPlan(html) {
|
||||
const infos = {};
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const data = [];
|
||||
const tables = $("table.mon_list");
|
||||
tables.each((tableIndex, tableElement) => {
|
||||
// Extract the date, weekday and a/b week from the title
|
||||
const title = $(".mon_title").text().split(" ");
|
||||
const title = $(tableElement)
|
||||
.parent()
|
||||
.siblings(".mon_title")
|
||||
.text()
|
||||
.split(" ");
|
||||
const rawDate = title[0];
|
||||
const date = rawDate
|
||||
.split(".")
|
||||
.reverse()
|
||||
.map((e) => e.padStart(2, 0))
|
||||
.join("-");
|
||||
|
||||
if (tableIndex == 0) {
|
||||
infos.date = new Date(date).setUTCHours(0, 0, 0, 0);
|
||||
infos.week = title[3];
|
||||
|
||||
// Get the export timestamp
|
||||
const rawTimestamp = $(".mon_head td")
|
||||
const rawTimestamp = $(tableElement)
|
||||
.parent()
|
||||
.parent()
|
||||
.siblings(".mon_head")
|
||||
.find("td")
|
||||
.text()
|
||||
.split("Stand: ")[1]
|
||||
.replace(/[\s\n]*$/g, "");
|
||||
const exportDate = rawTimestamp.split(" ")[0].split(".").reverse().join("-");
|
||||
const exportDate = rawTimestamp
|
||||
.split(" ")[0]
|
||||
.split(".")
|
||||
.reverse()
|
||||
.join("-");
|
||||
const timestamp = exportDate + " " + rawTimestamp.split(" ")[1];
|
||||
infos.updatedAt = new Date(timestamp).getTime();
|
||||
|
||||
const data = [];
|
||||
} else {
|
||||
// If there are multiple days in one file,
|
||||
// ignore all except the first one
|
||||
if (new Date(date).setUTCHours(0, 0, 0, 0) != infos.date) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const titles = [];
|
||||
const titleElements = $("table.mon_list tr.list th");
|
||||
const titleElements = $(tableElement).find("tr.list th");
|
||||
titleElements.each((index, titleElement) => {
|
||||
const title = $(titleElement).text();
|
||||
titles[index] = titleTranslations[title];
|
||||
});
|
||||
|
||||
const subsitutionTable = $("table.mon_list tr.list");
|
||||
const subsitutionTable = $(tableElement).find("tr.list");
|
||||
// Loop through each table row
|
||||
subsitutionTable.each((_rowcnt, row) => {
|
||||
const rowData = {};
|
||||
@ -83,6 +105,7 @@ export function parseSubstitutionPlan(html) {
|
||||
data.push({ ...rowData });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
infos.changes = data;
|
||||
return infos;
|
||||
|
Reference in New Issue
Block a user