Prvotní nástřel fungující aplikace
This commit is contained in:
@@ -6,7 +6,7 @@ import fs from 'fs';
|
||||
|
||||
type PizzaSize = {
|
||||
size: string,
|
||||
pizzaPrice: string,
|
||||
pizzaPrice: number,
|
||||
boxPrice: number,
|
||||
price: number
|
||||
}
|
||||
@@ -21,12 +21,15 @@ type Pizza = {
|
||||
const baseUrl = 'https://www.pizzachefie.cz';
|
||||
const pizzyUrl = `${baseUrl}/pizzy.html?pobocka=plzen`;
|
||||
|
||||
// URL na Food API - získání jídelních lístků restaurací
|
||||
const foodUrl = process.env.FOOD_API_URL || 'http://localhost:3002';
|
||||
|
||||
const buildPizzaUrl = (pizzaUrl: string) => {
|
||||
return `${baseUrl}/${pizzaUrl}`;
|
||||
}
|
||||
|
||||
// Ceny krabic dle velikosti
|
||||
const boxPrices = {
|
||||
const boxPrices: { [key: string]: number } = {
|
||||
"30cm": 13,
|
||||
"35cm": 15,
|
||||
"40cm": 18,
|
||||
@@ -55,19 +58,20 @@ const downloadPizzy = async () => {
|
||||
// Název
|
||||
const name = $('.produkt > h2', pizzaHtml).first().text()
|
||||
// Přísady
|
||||
const ingredients = []
|
||||
const ingredients: string[] = []
|
||||
const ingredientsHtml = $('.prisady > li', pizzaHtml);
|
||||
ingredientsHtml.each((i, elm) => {
|
||||
ingredients.push($(elm).text());
|
||||
})
|
||||
// Velikosti
|
||||
const sizes = [];
|
||||
const sizes: PizzaSize[] = [];
|
||||
const a = $('.varianty > li > a', pizzaHtml);
|
||||
a.each((i, elm) => {
|
||||
const size = $('span', elm).text();
|
||||
const priceKc = $(elm).text().split(size).pop().trim();
|
||||
const price = Number.parseInt(priceKc.split(" Kč")[0]);
|
||||
sizes.push({ size: size, pizzaPrice: price, boxPrice: boxPrices[size], price: price + boxPrices[size] });
|
||||
// TODO nedoděláno
|
||||
// const size = $('span', elm).text();
|
||||
// const priceKc = $(elm).text().split(size).pop().trim();
|
||||
// const price = Number.parseInt(priceKc.split(" Kč")[0]);
|
||||
// sizes.push({ size: size, pizzaPrice: price, boxPrice: boxPrices[size], price: price + boxPrices[size] });
|
||||
})
|
||||
result.push({
|
||||
name: name,
|
||||
@@ -101,6 +105,15 @@ export const fetchPizzy = async () => {
|
||||
console.log(`Zapsán ${dataPath}`);
|
||||
return pizzy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO tohle sem absolutně nepatří! dát do vlastní servisky!
|
||||
export const fetchFood = async () => {
|
||||
try {
|
||||
const json = await rp(foodUrl);
|
||||
return JSON.parse(json);
|
||||
} catch (error) {
|
||||
console.error("Chyba při volání Food API", error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user