Oprava parsování Sladovnická a TechTower
This commit is contained in:
parent
8285dd2780
commit
be4cee4cdb
@ -100,7 +100,7 @@ export const getMenuSladovnicka = async (firstDayOfWeek: Date, mock: boolean = f
|
|||||||
const html = await getHtml(SLADOVNICKA_URL);
|
const html = await getHtml(SLADOVNICKA_URL);
|
||||||
const $ = load(html);
|
const $ = load(html);
|
||||||
|
|
||||||
// Nejdříve zjistíme, které dny jsou k dispozici z tab elementů
|
// Zjistíme, které dny jsou k dispozici z tab elementů
|
||||||
const tabElements = $('#daily-menu-tab-list').children('button[id^="daily-menu-tab-"]');
|
const tabElements = $('#daily-menu-tab-list').children('button[id^="daily-menu-tab-"]');
|
||||||
const availableDays: { [dayIndex: number]: number } = {}; // mapování dayIndex -> contentIndex
|
const availableDays: { [dayIndex: number]: number } = {}; // mapování dayIndex -> contentIndex
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export const getMenuSladovnicka = async (firstDayOfWeek: Date, mock: boolean = f
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const menuContentElements = $('#daily-menu-content-list').children('[id^="daily-menu-content-"]');
|
const menuContentElements = $('#daily-menu-content-list').children('.daily-menu-content__content').not('.daily-menu-content__content--static');
|
||||||
|
|
||||||
const result: Food[][] = [];
|
const result: Food[][] = [];
|
||||||
|
|
||||||
@ -130,59 +130,32 @@ export const getMenuSladovnicka = async (firstDayOfWeek: Date, mock: boolean = f
|
|||||||
continue; // Přeskočíme, pokud content element neexistuje
|
continue; // Přeskočíme, pokud content element neexistuje
|
||||||
}
|
}
|
||||||
|
|
||||||
const dayChildren = $(menuContentElements[contentIndexNum]).children();
|
const contentElement = $(menuContentElements[contentIndexNum]);
|
||||||
|
const itemElement = contentElement.find('.daily-menu-content__item');
|
||||||
// Ověříme, že má element očekávanou strukturu
|
const table = itemElement.find('table.daily-menu-content__table tbody');
|
||||||
if (dayChildren.length < 2) {
|
const rows = table.children('tr');
|
||||||
console.warn(`Neočekávaný počet children v menu Sladovnické pro den ${dayIndexNum}: ${dayChildren.length}, očekávány alespoň 2 (polévka a hlavní jídlo)`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parsování polévky
|
|
||||||
const soupElement = dayChildren.get(0);
|
|
||||||
const soupTable = $(soupElement).find('table tbody tr');
|
|
||||||
const soupCells = soupTable.children('td');
|
|
||||||
if (soupCells.length !== 3) {
|
|
||||||
console.warn(`Neočekávaný počet buněk v tabulce polévky pro den ${dayIndexNum}: ${soupCells.length}, ale očekávány byly 3`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const soupAmount = sanitizeText($(soupCells.get(0)).text());
|
|
||||||
const soupNameRaw = sanitizeText($(soupCells.get(1)).text());
|
|
||||||
const soupPrice = sanitizeText($(soupCells.get(2)).text().replace(' ', '\xA0'));
|
|
||||||
const soupParsed = parseAllergens(soupNameRaw);
|
|
||||||
|
|
||||||
// Parsování hlavních jídel
|
|
||||||
const mainCourseElement = dayChildren.get(1);
|
|
||||||
const mainCourseTable = $(mainCourseElement).find('table tbody');
|
|
||||||
const mainCourseRows = mainCourseTable.children('tr');
|
|
||||||
|
|
||||||
const currentDayFood: Food[] = [];
|
const currentDayFood: Food[] = [];
|
||||||
|
|
||||||
// Přidáme polévku do seznamu jídel
|
// Projdeme všechny řádky - první je polévka, zbytek jsou hlavní jídla
|
||||||
currentDayFood.push({
|
rows.each((i, row) => {
|
||||||
amount: soupAmount,
|
|
||||||
name: soupParsed.cleanName,
|
|
||||||
price: soupPrice,
|
|
||||||
isSoup: true,
|
|
||||||
allergens: soupParsed.allergens.length > 0 ? soupParsed.allergens : undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Projdeme všechny řádky hlavních jídel
|
|
||||||
mainCourseRows.each((i, row) => {
|
|
||||||
const cells = $(row).children('td');
|
const cells = $(row).children('td');
|
||||||
|
if (cells.length !== 3) {
|
||||||
|
return; // Přeskočíme řádky s nesprávnou strukturou
|
||||||
|
}
|
||||||
|
|
||||||
const amount = sanitizeText($(cells.get(0)).text());
|
const amount = sanitizeText($(cells.get(0)).text());
|
||||||
const nameRaw = sanitizeText($(cells.get(1)).text());
|
const nameRaw = sanitizeText($(cells.get(1)).text());
|
||||||
const price = sanitizeText($(cells.get(2)).text().replace(' ', '\xA0'));
|
const price = sanitizeText($(cells.get(2)).text().replace(' ', '\xA0'));
|
||||||
const parsed = parseAllergens(nameRaw);
|
const parsed = parseAllergens(nameRaw);
|
||||||
|
|
||||||
// Přeskočíme prázdné řádky (první řádek může být prázdný)
|
// Přeskočíme prázdné řádky
|
||||||
if (parsed.cleanName.trim().length > 0) {
|
if (parsed.cleanName.trim().length > 0) {
|
||||||
currentDayFood.push({
|
currentDayFood.push({
|
||||||
amount,
|
amount,
|
||||||
name: parsed.cleanName,
|
name: parsed.cleanName,
|
||||||
price,
|
price,
|
||||||
isSoup: false,
|
isSoup: i === 0, // První řádek je polévka
|
||||||
allergens: parsed.allergens.length > 0 ? parsed.allergens : undefined,
|
allergens: parsed.allergens.length > 0 ? parsed.allergens : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -351,6 +324,11 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
|||||||
const split = [tmp.slice(0, -2).join(' ')].concat(tmp.slice(-2));
|
const split = [tmp.slice(0, -2).join(' ')].concat(tmp.slice(-2));
|
||||||
price = `${split.slice(1)[0]}\xA0Kč`
|
price = `${split.slice(1)[0]}\xA0Kč`
|
||||||
nameRaw = split[0].replace('•', '');
|
nameRaw = split[0].replace('•', '');
|
||||||
|
} else if (text.toLowerCase().endsWith(',-')) {
|
||||||
|
const tmp = text.replace('\xA0', ' ').split(' ');
|
||||||
|
const split = [tmp.slice(0, -1).join(' ')].concat(tmp.slice(-1));
|
||||||
|
price = `${split.slice(1)[0].replace(',-', '')}\xA0Kč`
|
||||||
|
nameRaw = split[0].replace('•', '');
|
||||||
}
|
}
|
||||||
if (nameRaw.endsWith('–')) {
|
if (nameRaw.endsWith('–')) {
|
||||||
nameRaw = nameRaw.slice(0, -1).trim();
|
nameRaw = nameRaw.slice(0, -1).trim();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user