From fdf1ae938fa9bdb2ec7a580a280964e9c65bdcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20H=C3=A1jek?= Date: Tue, 28 Jan 2025 22:20:44 +0100 Subject: [PATCH] =?UTF-8?q?Na=C4=8Dten=C3=AD=20menu=20cel=C3=A9ho=20t?= =?UTF-8?q?=C3=BDdne=20restaurace=20Zast=C3=A1vka=20u=20Michala?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/restaurants.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/src/restaurants.ts b/server/src/restaurants.ts index 66bdda9..9d12561 100644 --- a/server/src/restaurants.ts +++ b/server/src/restaurants.ts @@ -2,7 +2,7 @@ import axios from "axios"; import { load } from 'cheerio'; import { Food } from "../../types"; import {getMenuSladovnickaMock, getMenuTechTowerMock, getMenuUMotlikuMock, getMenuZastavkaUmichalaMock} from "./mock"; -import {formatDate, getDayOfWeekIndex, getIsWeekend} from "./utils"; +import {formatDate} from "./utils"; // Fráze v názvech jídel, které naznačují že se jedná o polévku const SOUP_NAMES = [ @@ -344,13 +344,16 @@ export const getMenuZastavkaUmichala = async (firstDayOfWeek: Date, mock: boolea } const nowDate = new Date().getDate(); + const headers = { + "Cookie": "_nss=1; PHPSESSID=9e37de17e0326b0942613d6e67a30e69", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36", + }; const result: Food[][] = []; for (let dayIndex = 0; dayIndex < 5; dayIndex++) { const currentDate = new Date(firstDayOfWeek); currentDate.setDate(firstDayOfWeek.getDate() + dayIndex); - // if (currentDate < now) { - if (currentDate.getDate() !== nowDate) { + if (currentDate.getDate() < nowDate || (currentDate.getDate() === nowDate && new Date().getHours() >= 14)) { result[dayIndex] = [{ amount: undefined, name: "Pro tento den není uveřejněna nabídka jídel", @@ -359,13 +362,13 @@ export const getMenuZastavkaUmichala = async (firstDayOfWeek: Date, mock: boolea }]; continue; } else { - // let dateString = formatDate(currentDate, 'DD.MM.YYYY'); - // const html = await getHtml(ZASTAVKAUMICHALA_URL + '/?do=dailyMenu-changeDate&dailyMenu-dateString=' + dateString); - const html = await getHtml(ZASTAVKAUMICHALA_URL); + const url = (currentDate.getDate() === nowDate) ? + ZASTAVKAUMICHALA_URL : ZASTAVKAUMICHALA_URL + '/?do=dailyMenu-changeDate&dailyMenu-dateString=' + formatDate(currentDate, 'DD.MM.YYYY'); + const html = await axios.get(url, { + headers, + }).then(res => res.data).then(content => content); const $ = load(html); - // const row = $($('.foodsList li')[0]).text(); - const currentDayFood: Food[] = []; $('.foodsList li').each((index, element) => { currentDayFood.push({