Vylepšení parsování U Motlíků
Nově je počítáno s případy, kdy na stránkách existuje menu pro více týdnů současně.
This commit is contained in:
parent
7024c75f37
commit
f85d19bbd6
@ -360,8 +360,7 @@ function App() {
|
|||||||
<Alert variant={'primary'}>
|
<Alert variant={'primary'}>
|
||||||
Poslední změny:
|
Poslední změny:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Zobrazování data poslední aktualizace menu</li>
|
<li>Tolerance existence menu na více týdnů pro restauraci U Motlíků</li>
|
||||||
<li>Přidání favicony</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</Alert>
|
</Alert>
|
||||||
{dayIndex != null &&
|
{dayIndex != null &&
|
||||||
|
@ -157,8 +157,26 @@ export const getMenuUMotliku = async (firstDayOfWeek: Date, mock: boolean = fals
|
|||||||
const html = await getHtml(U_MOTLIKU_URL);
|
const html = await getHtml(U_MOTLIKU_URL);
|
||||||
const $ = load(html);
|
const $ = load(html);
|
||||||
|
|
||||||
const table = $('table.table.table-hover.Xtable-striped').first();
|
// Najdeme první tabulku, nad kterou je v H3 datum začínající prvním dnem aktuálního týdne
|
||||||
const body = table.children().first();
|
// To může selhat mnoha způsoby, ale ty nemá cenu řešit dokud nenastanou
|
||||||
|
const tables = $('table.table.table-hover.Xtable-striped');
|
||||||
|
let usedTable;
|
||||||
|
const firstDayOfWeekString = `${firstDayOfWeek.getDate()}.${firstDayOfWeek.getMonth() + 1}.`;
|
||||||
|
for (const tableNode of tables) {
|
||||||
|
const table = $(tableNode);
|
||||||
|
const h3 = table.parent().prev();
|
||||||
|
const s1 = h3.text().split("-")[0].split(".");
|
||||||
|
const foundFirstDayString = `${s1[0]}.${s1[1]}.`;
|
||||||
|
if (foundFirstDayString === firstDayOfWeekString) {
|
||||||
|
usedTable = table;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usedTable == null) {
|
||||||
|
throw Error(`Nepodařilo se najít tabulku pro datum ${firstDayOfWeekString}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = usedTable.children().first();
|
||||||
const rows = body.children();
|
const rows = body.children();
|
||||||
|
|
||||||
const result: Food[][] = [];
|
const result: Food[][] = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user