Načtení menu celého týdne restaurace Zastávka u Michala
This commit is contained in:
parent
57c22958be
commit
fdf1ae938f
@ -2,7 +2,7 @@ import axios from "axios";
|
|||||||
import { load } from 'cheerio';
|
import { load } from 'cheerio';
|
||||||
import { Food } from "../../types";
|
import { Food } from "../../types";
|
||||||
import {getMenuSladovnickaMock, getMenuTechTowerMock, getMenuUMotlikuMock, getMenuZastavkaUmichalaMock} from "./mock";
|
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
|
// Fráze v názvech jídel, které naznačují že se jedná o polévku
|
||||||
const SOUP_NAMES = [
|
const SOUP_NAMES = [
|
||||||
@ -344,13 +344,16 @@ export const getMenuZastavkaUmichala = async (firstDayOfWeek: Date, mock: boolea
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nowDate = new Date().getDate();
|
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[][] = [];
|
const result: Food[][] = [];
|
||||||
for (let dayIndex = 0; dayIndex < 5; dayIndex++) {
|
for (let dayIndex = 0; dayIndex < 5; dayIndex++) {
|
||||||
const currentDate = new Date(firstDayOfWeek);
|
const currentDate = new Date(firstDayOfWeek);
|
||||||
currentDate.setDate(firstDayOfWeek.getDate() + dayIndex);
|
currentDate.setDate(firstDayOfWeek.getDate() + dayIndex);
|
||||||
|
|
||||||
// if (currentDate < now) {
|
if (currentDate.getDate() < nowDate || (currentDate.getDate() === nowDate && new Date().getHours() >= 14)) {
|
||||||
if (currentDate.getDate() !== nowDate) {
|
|
||||||
result[dayIndex] = [{
|
result[dayIndex] = [{
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
name: "Pro tento den není uveřejněna nabídka jídel",
|
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;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// let dateString = formatDate(currentDate, 'DD.MM.YYYY');
|
const url = (currentDate.getDate() === nowDate) ?
|
||||||
// const html = await getHtml(ZASTAVKAUMICHALA_URL + '/?do=dailyMenu-changeDate&dailyMenu-dateString=' + dateString);
|
ZASTAVKAUMICHALA_URL : ZASTAVKAUMICHALA_URL + '/?do=dailyMenu-changeDate&dailyMenu-dateString=' + formatDate(currentDate, 'DD.MM.YYYY');
|
||||||
const html = await getHtml(ZASTAVKAUMICHALA_URL);
|
const html = await axios.get(url, {
|
||||||
|
headers,
|
||||||
|
}).then(res => res.data).then(content => content);
|
||||||
const $ = load(html);
|
const $ = load(html);
|
||||||
|
|
||||||
// const row = $($('.foodsList li')[0]).text();
|
|
||||||
|
|
||||||
const currentDayFood: Food[] = [];
|
const currentDayFood: Food[] = [];
|
||||||
$('.foodsList li').each((index, element) => {
|
$('.foodsList li').each((index, element) => {
|
||||||
currentDayFood.push({
|
currentDayFood.push({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user