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