🚑 Fix parser crash if column order is different

This commit is contained in:
2022-08-21 13:16:43 +02:00
parent 0e46c8908e
commit fa9de85eed

View File

@ -1,15 +1,15 @@
import * as cheerio from "cheerio"; import * as cheerio from "cheerio";
const titles = [ const titleTranslations = {
"class", "Klasse(n)": "class",
"date", Datum: "date",
"lesson", Stunde: "lesson",
"teacher", "(Lehrer)": "teacher",
"changedTeacher", Vertreter: "changedTeacher",
"subject", Fach: "subject",
"room", Raum: "room",
"type", Art: "type",
"notes", Text: "notes",
]; };
export function parseSubstitutionPlan(html) { export function parseSubstitutionPlan(html) {
const infos = {}; const infos = {};
@ -36,6 +36,14 @@ export function parseSubstitutionPlan(html) {
infos.updatedAt = new Date(timestamp).getTime(); infos.updatedAt = new Date(timestamp).getTime();
const data = []; const data = [];
const titles = [];
const titleElements = $("table.mon_list tr.list th");
titleElements.each((index, titleElement) => {
const title = $(titleElement).text();
titles[index] = titleTranslations[title];
});
const subsitutionTable = $("table.mon_list tr.list"); const subsitutionTable = $("table.mon_list tr.list");
// Loop through each table row // Loop through each table row
subsitutionTable.each((_rowcnt, row) => { subsitutionTable.each((_rowcnt, row) => {