diff --git a/client/src/App.tsx b/client/src/App.tsx index c3cb4ae..5bb0713 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -360,6 +360,7 @@ function App() { {dayIndex != null && diff --git a/server/src/restaurants.ts b/server/src/restaurants.ts index 0cef7a3..fd2899d 100644 --- a/server/src/restaurants.ts +++ b/server/src/restaurants.ts @@ -235,46 +235,46 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal if (!font) { throw Error('Chyba: nenalezen pro obědy v HTML Techtower.'); } + + const result: Food[][] = []; // TODO validovat, že v textu nalezeného je rozsah, do kterého spadá vstupní datum const siblings = $(font).parent().parent().siblings(); let parsing = false; - const result: Food[][] = []; - // TODO toto je kvůli poslednímu "línému" refaktoru neoptimální, stačilo by to projít jedním cyklem - for (let dayIndex = 0; dayIndex < 5; dayIndex++) { - if (!(dayIndex in result)) { - result[dayIndex] = []; - } - for (let i = 0; i < siblings.length; i++) { - const text = $(siblings.get(i)).text().trim().replace('\t', '').replace('\n', ' '); - if (DAYS_IN_WEEK.includes(text)) { - if (text === DAYS_IN_WEEK[dayIndex]) { - // Našli jsme dnešní den, odtud začínáme parsovat jídla - parsing = true; - continue - } else if (parsing) { - // Už parsujeme jídla, ale narazili jsme na následující den - končíme - break; - } + let currentDayIndex = 0; + for (let i = 0; i < siblings.length; i++) { + const text = $(siblings.get(i)).text().trim().replace('\t', '').replace('\n', ' '); + if (DAYS_IN_WEEK.includes(text)) { + if (text === DAYS_IN_WEEK[currentDayIndex]) { + // Našli jsme dnešní den, odtud začínáme parsovat jídla + parsing = true; + continue } else if (parsing) { - if (text.length == 0) { - // Prázdná řádka - končíme (je za pátečním menu TechTower) - break; - } - let price = '? Kč'; - let name = text; - if (text.toLowerCase().endsWith('kč')) { - const tmp = text.replace('\xA0', ' ').split(' '); - const split = [tmp.slice(0, -2).join(' ')].concat(tmp.slice(-2)); - price = `${split.slice(1)[0]}\xA0Kč` - name = split[0] - } - result[dayIndex].push({ - amount: '-', - name, - price, - isSoup: isTextSoupName(name), - }) + // Už parsujeme jídla, ale narazili jsme na následující den - posouváme index + currentDayIndex += 1; + continue; } + } else if (parsing) { + if (text.length == 0) { + // Prázdná řádka - končíme (je za pátečním menu TechTower) + break; + } + let price = '? Kč'; + let name = text; + if (text.toLowerCase().endsWith('kč')) { + const tmp = text.replace('\xA0', ' ').split(' '); + const split = [tmp.slice(0, -2).join(' ')].concat(tmp.slice(-2)); + price = `${split.slice(1)[0]}\xA0Kč` + name = split[0] + } + if (result[currentDayIndex] == null) { + result[currentDayIndex] = []; + } + result[currentDayIndex].push({ + amount: '-', + name, + price, + isSoup: isTextSoupName(name), + }) } } return result;