note7 commited on
Commit
a869703
·
verified ·
1 Parent(s): 88edcd6

Add 2 files

Browse files
Files changed (2) hide show
  1. index.html +107 -123
  2. prompts.txt +2 -1
index.html CHANGED
@@ -159,11 +159,10 @@
159
  </div>
160
 
161
  <script>
162
- // API Configuration
163
- const API_KEY = 'd8a3d9c1a6msh1a2c6c5a7e8b9f0p1b3c4jsn1a2b3c4d5e6f'; // Replace with your Spoonacular API key
164
- const API_URL = 'https://api.spoonacular.com/recipes/complexSearch';
165
- const RECIPE_INFO_URL = 'https://api.spoonacular.com/recipes/{id}/information';
166
- const NUTRITION_INFO_URL = 'https://api.spoonacular.com/recipes/{id}/nutritionWidget.json';
167
 
168
  // Global variables
169
  let currentMenu = [];
@@ -255,7 +254,7 @@
255
  });
256
 
257
  // Add ingredients to shopping list
258
- addToShoppingList(recipe.extendedIngredients);
259
  }
260
  }
261
 
@@ -270,61 +269,59 @@
270
  }
271
  }
272
 
273
- // Fetch healthy recipe from API
274
  async function fetchHealthyRecipe(mealType) {
275
- const diet = 'vegetarian'; // Can be changed to 'vegan', 'gluten free', etc.
276
- const intolerances = 'dairy'; // Common for older adults
 
 
 
 
 
 
277
  const maxCalories = mealType === 'breakfast' ? 400 : 600;
278
  const minProtein = mealType === 'breakfast' ? 10 : 20;
279
 
280
  const params = new URLSearchParams({
281
- apiKey: API_KEY,
282
- diet,
283
- intolerances,
284
- maxCalories,
285
- minProtein,
286
- number: 1,
287
- addRecipeInformation: true,
288
- fillIngredients: true,
289
- instructionsRequired: true,
290
- sort: 'healthiness',
291
- type: mealType
292
  });
293
 
294
  try {
295
- // First search for recipes
296
- const searchResponse = await axios.get(`${API_URL}?${params}`);
297
- if (searchResponse.data.results.length === 0) {
 
298
  console.warn(`No recipes found for ${mealType}`);
299
  return null;
300
  }
301
 
302
- const recipeId = searchResponse.data.results[0].id;
303
-
304
- // Then get detailed information
305
- const infoResponse = await axios.get(
306
- RECIPE_INFO_URL.replace('{id}', recipeId),
307
- { params: { apiKey: API_KEY } }
308
- );
309
 
310
- // Get nutrition information
311
- const nutritionResponse = await axios.get(
312
- NUTRITION_INFO_URL.replace('{id}', recipeId),
313
- { params: { apiKey: API_KEY } }
314
- );
315
-
316
- // Combine all data
317
  return {
318
- id: recipeId,
319
- title: infoResponse.data.title,
320
- image: infoResponse.data.image,
321
- readyInMinutes: infoResponse.data.readyInMinutes,
322
- servings: infoResponse.data.servings,
323
- sourceUrl: infoResponse.data.sourceUrl,
324
- sourceName: infoResponse.data.sourceName,
325
- extendedIngredients: infoResponse.data.extendedIngredients,
326
- instructions: infoResponse.data.instructions,
327
- nutrition: nutritionResponse.data
 
 
 
 
 
328
  };
329
  } catch (error) {
330
  console.error('Error fetching recipe:', error);
@@ -335,9 +332,9 @@
335
  // Add ingredients to shopping list
336
  function addToShoppingList(ingredients) {
337
  ingredients.forEach(ingredient => {
338
- const name = ingredient.nameClean || ingredient.name;
339
- const amount = ingredient.amount;
340
- const unit = ingredient.unit;
341
 
342
  if (shoppingList[name]) {
343
  shoppingList[name].amount += amount;
@@ -345,12 +342,26 @@
345
  shoppingList[name] = {
346
  amount,
347
  unit,
348
- aisle: ingredient.aisle
349
  };
350
  }
351
  });
352
  }
353
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  // Render recipes
355
  function renderRecipes(recipes) {
356
  if (recipes.length === 0) {
@@ -366,12 +377,6 @@
366
  recipeCard.dataset.day = recipe.day;
367
  recipeCard.dataset.mealType = recipe.mealType;
368
 
369
- // Nutrition badges
370
- const calories = Math.round(recipe.nutrition.calories.replace(/[^\d.]/g, ''));
371
- const protein = Math.round(recipe.nutrition.protein.replace(/[^\d.]/g, ''));
372
- const carbs = Math.round(recipe.nutrition.carbs.replace(/[^\d.]/g, ''));
373
- const fat = Math.round(recipe.nutrition.fat.replace(/[^\d.]/g, ''));
374
-
375
  recipeCard.innerHTML = `
376
  <div class="md:flex">
377
  <div class="md:w-1/3">
@@ -387,33 +392,33 @@
387
  <h3 class="text-xl font-bold text-gray-800 mb-2">${recipe.title}</h3>
388
  </div>
389
  <div class="flex items-center gap-1">
390
- <span class="text-xs text-gray-500">${recipe.readyInMinutes} min</span>
391
- <i class="fas fa-clock text-gray-400"></i>
392
  </div>
393
  </div>
394
 
395
  <div class="flex flex-wrap gap-2 my-3">
396
  <div class="nutrition-badge bg-red-100 text-red-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
397
- <i class="fas fa-fire"></i> ${calories} kcal
398
  </div>
399
  <div class="nutrition-badge bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
400
- <i class="fas fa-dumbbell"></i> ${protein}g proteína
401
  </div>
402
  <div class="nutrition-badge bg-yellow-100 text-yellow-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
403
- <i class="fas fa-bread-slice"></i> ${carbs}g carbos
404
  </div>
405
  <div class="nutrition-badge bg-orange-100 text-orange-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
406
- <i class="fas fa-oil-can"></i> ${fat}g grasas
407
  </div>
408
  </div>
409
 
410
  <div class="mb-4">
411
  <h4 class="font-medium text-gray-700 mb-2">Ingredientes (${recipe.servings} porciones):</h4>
412
  <ul class="grid grid-cols-1 sm:grid-cols-2 gap-1 text-sm text-gray-600">
413
- ${recipe.extendedIngredients.map(ing =>
414
  `<li class="flex items-start">
415
  <i class="fas fa-check-circle text-green-400 mt-1 mr-2 text-xs"></i>
416
- <span>${ing.original}</span>
417
  </li>`
418
  ).join('')}
419
  </ul>
@@ -421,7 +426,9 @@
421
 
422
  <div class="mb-4">
423
  <h4 class="font-medium text-gray-700 mb-2">Instrucciones:</h4>
424
- <div class="text-sm text-gray-600">${formatInstructions(recipe.instructions)}</div>
 
 
425
  </div>
426
 
427
  ${recipe.sourceUrl ? `
@@ -440,20 +447,6 @@
440
  });
441
  }
442
 
443
- // Format recipe instructions
444
- function formatInstructions(instructions) {
445
- if (!instructions) return 'No hay instrucciones disponibles.';
446
-
447
- // Remove HTML tags
448
- let text = instructions.replace(/<[^>]*>/g, '');
449
-
450
- // Split into paragraphs
451
- const paragraphs = text.split(/\r?\n/).filter(p => p.trim().length > 0);
452
-
453
- // Format each paragraph
454
- return paragraphs.map(p => `<p class="mb-2">${p}</p>`).join('');
455
- }
456
-
457
  // Filter recipes by type
458
  function filterRecipes(type) {
459
  const allRecipes = document.querySelectorAll('.recipe-card');
@@ -499,7 +492,7 @@
499
  }
500
 
501
  aisles[aisle].push({
502
- name,
503
  amount: data.amount,
504
  unit: data.unit
505
  });
@@ -535,6 +528,11 @@
535
  shoppingModal.classList.remove('hidden');
536
  }
537
 
 
 
 
 
 
538
  // Print shopping list
539
  function printShoppingList() {
540
  const printContent = shoppingListContent.innerHTML;
@@ -601,12 +599,7 @@
601
  doc.setFontSize(10);
602
  doc.setTextColor(0, 0, 0);
603
 
604
- const calories = recipe.nutrition.calories.replace(/[^\d.]/g, '');
605
- const protein = recipe.nutrition.protein.replace(/[^\d.]/g, '');
606
- const carbs = recipe.nutrition.carbs.replace(/[^\d.]/g, '');
607
- const fat = recipe.nutrition.fat.replace(/[^\d.]/g, '');
608
-
609
- doc.text(`Nutrición por porción: ${calories} kcal | ${protein}g proteína | ${carbs}g carbohidratos | ${fat}g grasas`, 20, y);
610
  y += 8;
611
 
612
  // Ingredients
@@ -616,41 +609,38 @@
616
  y += 6;
617
 
618
  doc.setFontSize(10);
619
- recipe.extendedIngredients.forEach(ing => {
620
  if (y > 270) {
621
  doc.addPage();
622
  y = 20;
623
  page++;
624
  }
625
 
626
- doc.text(`- ${ing.original}`, 25, y);
627
  y += 6;
628
  });
629
 
630
  y += 6;
631
 
632
  // Instructions
633
- if (recipe.instructions) {
634
- doc.setFontSize(12);
635
- doc.setTextColor(55, 65, 81);
636
- doc.text('Instrucciones:', 20, y);
637
- y += 6;
638
-
639
- doc.setFontSize(10);
640
- const instructions = formatInstructions(recipe.instructions).replace(/<[^>]*>/g, '');
641
- const lines = doc.splitTextToSize(instructions, 170);
 
 
 
 
 
642
 
643
- lines.forEach(line => {
644
- if (y > 270) {
645
- doc.addPage();
646
- y = 20;
647
- page++;
648
- }
649
-
650
- doc.text(line, 25, y);
651
- y += 6;
652
- });
653
- }
654
 
655
  y += 10;
656
 
@@ -674,18 +664,12 @@
674
  return;
675
  }
676
 
677
- let csv = 'Día,Tipo,Receta,Calorías,Proteína (g),Carbohidratos (g),Grasas (g),Ingredientes,Instrucciones,URL\n';
678
 
679
  currentMenu.forEach(recipe => {
680
- const calories = recipe.nutrition.calories.replace(/[^\d.]/g, '');
681
- const protein = recipe.nutrition.protein.replace(/[^\d.]/g, '');
682
- const carbs = recipe.nutrition.carbs.replace(/[^\d.]/g, '');
683
- const fat = recipe.nutrition.fat.replace(/[^\d.]/g, '');
684
-
685
- const ingredients = recipe.extendedIngredients.map(ing => ing.original).join(' | ');
686
- const instructions = recipe.instructions ? recipe.instructions.replace(/<[^>]*>/g, '').replace(/"/g, '""').replace(/\n/g, ' ') : '';
687
 
688
- csv += `"${recipe.day}","${recipe.mealType === 'breakfast' ? 'Desayuno' : 'Cena'}","${recipe.title}","${calories}","${protein}","${carbs}","${fat}","${ingredients}","${instructions}","${recipe.sourceUrl || ''}"\n`;
689
  });
690
 
691
  // Create download link
@@ -735,7 +719,7 @@
735
  }
736
 
737
  aisles[aisle].push({
738
- name,
739
  amount: data.amount,
740
  unit: data.unit
741
  });
@@ -799,10 +783,10 @@
799
  let totalFat = 0;
800
 
801
  currentMenu.forEach(recipe => {
802
- totalCalories += parseFloat(recipe.nutrition.calories.replace(/[^\d.]/g, ''));
803
- totalProtein += parseFloat(recipe.nutrition.protein.replace(/[^\d.]/g, ''));
804
- totalCarbs += parseFloat(recipe.nutrition.carbs.replace(/[^\d.]/g, ''));
805
- totalFat += parseFloat(recipe.nutrition.fat.replace(/[^\d.]/g, ''));
806
  });
807
 
808
  const avgCal = Math.round(totalCalories / currentMenu.length);
 
159
  </div>
160
 
161
  <script>
162
+ // API Configuration for Edamam
163
+ const APP_ID = '1b8ad4ca'; // Your Edamam app ID
164
+ const APP_KEY = 'd3b5e2a1c6e5b8a1f5e9c7a8b3d4e5f'; // Your Edamam API key
165
+ const API_URL = 'https://api.edamam.com/api/recipes/v2';
 
166
 
167
  // Global variables
168
  let currentMenu = [];
 
254
  });
255
 
256
  // Add ingredients to shopping list
257
+ addToShoppingList(recipe.ingredients);
258
  }
259
  }
260
 
 
269
  }
270
  }
271
 
272
+ // Fetch healthy recipe from Edamam API
273
  async function fetchHealthyRecipe(mealType) {
274
+ const healthLabels = [
275
+ 'low-sugar',
276
+ 'low-fat-abs',
277
+ 'sugar-conscious',
278
+ 'low-potassium',
279
+ 'kidney-friendly'
280
+ ].join('&health=');
281
+
282
  const maxCalories = mealType === 'breakfast' ? 400 : 600;
283
  const minProtein = mealType === 'breakfast' ? 10 : 20;
284
 
285
  const params = new URLSearchParams({
286
+ type: 'public',
287
+ app_id: APP_ID,
288
+ app_key: APP_KEY,
289
+ diet: 'balanced',
290
+ health: healthLabels,
291
+ calories: `0-${maxCalories}`,
292
+ nutrient: `PROCNT.min=${minProtein}`,
293
+ random: 'true',
294
+ field: ['uri', 'label', 'image', 'url', 'yield', 'ingredients', 'totalNutrients', 'totalDaily', 'digest'].join(',')
 
 
295
  });
296
 
297
  try {
298
+ // Search for recipes
299
+ const response = await axios.get(`${API_URL}?${params}`);
300
+
301
+ if (response.data.hits.length === 0) {
302
  console.warn(`No recipes found for ${mealType}`);
303
  return null;
304
  }
305
 
306
+ const recipeData = response.data.hits[0].recipe;
 
 
 
 
 
 
307
 
308
+ // Format recipe data for our app
 
 
 
 
 
 
309
  return {
310
+ id: recipeData.uri.split('#')[1], // Extract ID from URI
311
+ title: recipeData.label,
312
+ image: recipeData.image,
313
+ servings: recipeData.yield,
314
+ sourceUrl: recipeData.url,
315
+ sourceName: 'Edamam',
316
+ ingredients: recipeData.ingredients,
317
+ instructions: 'Ver instrucciones en el enlace original',
318
+ nutrition: {
319
+ calories: Math.round(recipeData.calories / recipeData.yield),
320
+ protein: Math.round(recipeData.totalNutrients.PROCNT.quantity / recipeData.yield),
321
+ carbs: Math.round(recipeData.totalNutrients.CHOCDF.quantity / recipeData.yield),
322
+ fat: Math.round(recipeData.totalNutrients.FAT.quantity / recipeData.yield),
323
+ fiber: Math.round(recipeData.totalNutrients.FIBTG.quantity / recipeData.yield)
324
+ }
325
  };
326
  } catch (error) {
327
  console.error('Error fetching recipe:', error);
 
332
  // Add ingredients to shopping list
333
  function addToShoppingList(ingredients) {
334
  ingredients.forEach(ingredient => {
335
+ const name = ingredient.food.toLowerCase();
336
+ const amount = ingredient.quantity;
337
+ const unit = ingredient.measure || 'unidad';
338
 
339
  if (shoppingList[name]) {
340
  shoppingList[name].amount += amount;
 
342
  shoppingList[name] = {
343
  amount,
344
  unit,
345
+ aisle: getIngredientAisle(ingredient.food)
346
  };
347
  }
348
  });
349
  }
350
 
351
+ // Simple function to categorize ingredients into aisles
352
+ function getIngredientAisle(ingredientName) {
353
+ const name = ingredientName.toLowerCase();
354
+
355
+ if (name.includes('leche') || name.includes('yogur') || name.includes('queso')) return 'Lácteos';
356
+ if (name.includes('pollo') || name.includes('carne') || name.includes('pescado') || name.includes('huevo')) return 'Carnicería/Pescadería';
357
+ if (name.includes('pan') || name.includes('arroz') || name.includes('pasta') || name.includes('harina')) return 'Panadería/Cereales';
358
+ if (name.includes('manzana') || name.includes('plátano') || name.includes('naranja') || name.includes('fruta')) return 'Frutas';
359
+ if (name.includes('zanahoria') || name.includes('cebolla') || name.includes('tomate') || name.includes('verdura')) return 'Verduras';
360
+ if (name.includes('aceite') || name.includes('vinagre') || name.includes('especia')) return 'Aceites/Especias';
361
+
362
+ return 'Otros';
363
+ }
364
+
365
  // Render recipes
366
  function renderRecipes(recipes) {
367
  if (recipes.length === 0) {
 
377
  recipeCard.dataset.day = recipe.day;
378
  recipeCard.dataset.mealType = recipe.mealType;
379
 
 
 
 
 
 
 
380
  recipeCard.innerHTML = `
381
  <div class="md:flex">
382
  <div class="md:w-1/3">
 
392
  <h3 class="text-xl font-bold text-gray-800 mb-2">${recipe.title}</h3>
393
  </div>
394
  <div class="flex items-center gap-1">
395
+ <span class="text-xs text-gray-500">${recipe.servings} porciones</span>
396
+ <i class="fas fa-utensils text-gray-400"></i>
397
  </div>
398
  </div>
399
 
400
  <div class="flex flex-wrap gap-2 my-3">
401
  <div class="nutrition-badge bg-red-100 text-red-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
402
+ <i class="fas fa-fire"></i> ${recipe.nutrition.calories} kcal
403
  </div>
404
  <div class="nutrition-badge bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
405
+ <i class="fas fa-dumbbell"></i> ${recipe.nutrition.protein}g proteína
406
  </div>
407
  <div class="nutrition-badge bg-yellow-100 text-yellow-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
408
+ <i class="fas fa-bread-slice"></i> ${recipe.nutrition.carbs}g carbos
409
  </div>
410
  <div class="nutrition-badge bg-orange-100 text-orange-800 px-3 py-1 rounded-full text-sm flex items-center gap-1">
411
+ <i class="fas fa-oil-can"></i> ${recipe.nutrition.fat}g grasas
412
  </div>
413
  </div>
414
 
415
  <div class="mb-4">
416
  <h4 class="font-medium text-gray-700 mb-2">Ingredientes (${recipe.servings} porciones):</h4>
417
  <ul class="grid grid-cols-1 sm:grid-cols-2 gap-1 text-sm text-gray-600">
418
+ ${recipe.ingredients.map(ing =>
419
  `<li class="flex items-start">
420
  <i class="fas fa-check-circle text-green-400 mt-1 mr-2 text-xs"></i>
421
+ <span>${ing.text}</span>
422
  </li>`
423
  ).join('')}
424
  </ul>
 
426
 
427
  <div class="mb-4">
428
  <h4 class="font-medium text-gray-700 mb-2">Instrucciones:</h4>
429
+ <div class="text-sm text-gray-600">
430
+ <p>Para ver las instrucciones completas, visita el enlace original de la receta.</p>
431
+ </div>
432
  </div>
433
 
434
  ${recipe.sourceUrl ? `
 
447
  });
448
  }
449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  // Filter recipes by type
451
  function filterRecipes(type) {
452
  const allRecipes = document.querySelectorAll('.recipe-card');
 
492
  }
493
 
494
  aisles[aisle].push({
495
+ name: capitalizeFirstLetter(name),
496
  amount: data.amount,
497
  unit: data.unit
498
  });
 
528
  shoppingModal.classList.remove('hidden');
529
  }
530
 
531
+ // Helper function to capitalize first letter
532
+ function capitalizeFirstLetter(string) {
533
+ return string.charAt(0).toUpperCase() + string.slice(1);
534
+ }
535
+
536
  // Print shopping list
537
  function printShoppingList() {
538
  const printContent = shoppingListContent.innerHTML;
 
599
  doc.setFontSize(10);
600
  doc.setTextColor(0, 0, 0);
601
 
602
+ doc.text(`Nutrición por porción: ${recipe.nutrition.calories} kcal | ${recipe.nutrition.protein}g proteína | ${recipe.nutrition.carbs}g carbohidratos | ${recipe.nutrition.fat}g grasas`, 20, y);
 
 
 
 
 
603
  y += 8;
604
 
605
  // Ingredients
 
609
  y += 6;
610
 
611
  doc.setFontSize(10);
612
+ recipe.ingredients.forEach(ing => {
613
  if (y > 270) {
614
  doc.addPage();
615
  y = 20;
616
  page++;
617
  }
618
 
619
+ doc.text(`- ${ing.text}`, 25, y);
620
  y += 6;
621
  });
622
 
623
  y += 6;
624
 
625
  // Instructions
626
+ doc.setFontSize(12);
627
+ doc.setTextColor(55, 65, 81);
628
+ doc.text('Instrucciones:', 20, y);
629
+ y += 6;
630
+
631
+ doc.setFontSize(10);
632
+ const lines = doc.splitTextToSize('Para ver las instrucciones completas, visita el enlace original de la receta.', 170);
633
+
634
+ lines.forEach(line => {
635
+ if (y > 270) {
636
+ doc.addPage();
637
+ y = 20;
638
+ page++;
639
+ }
640
 
641
+ doc.text(line, 25, y);
642
+ y += 6;
643
+ });
 
 
 
 
 
 
 
 
644
 
645
  y += 10;
646
 
 
664
  return;
665
  }
666
 
667
+ let csv = 'Día,Tipo,Receta,Calorías,Proteína (g),Carbohidratos (g),Grasas (g),Ingredientes,URL\n';
668
 
669
  currentMenu.forEach(recipe => {
670
+ const ingredients = recipe.ingredients.map(ing => ing.text).join(' | ');
 
 
 
 
 
 
671
 
672
+ csv += `"${recipe.day}","${recipe.mealType === 'breakfast' ? 'Desayuno' : 'Cena'}","${recipe.title}","${recipe.nutrition.calories}","${recipe.nutrition.protein}","${recipe.nutrition.carbs}","${recipe.nutrition.fat}","${ingredients}","${recipe.sourceUrl || ''}"\n`;
673
  });
674
 
675
  // Create download link
 
719
  }
720
 
721
  aisles[aisle].push({
722
+ name: capitalizeFirstLetter(name),
723
  amount: data.amount,
724
  unit: data.unit
725
  });
 
783
  let totalFat = 0;
784
 
785
  currentMenu.forEach(recipe => {
786
+ totalCalories += recipe.nutrition.calories;
787
+ totalProtein += recipe.nutrition.protein;
788
+ totalCarbs += recipe.nutrition.carbs;
789
+ totalFat += recipe.nutrition.fat;
790
  });
791
 
792
  const avgCal = Math.round(totalCalories / currentMenu.length);
prompts.txt CHANGED
@@ -1 +1,2 @@
1
- Una aplicacion html y javascript en local sin node y con flexbox, que pida recetas bajas en calorias para 30 dias (comida y cena) para personas de mas de 50 años, el menu tiene que ser equilibrado, además tiene que alimentarse de un api de recetas de internet. la aplicacion mostrará la receta, los ingredientes y si es posible de donde las ha sacado, cada comida indicará las calorias en una tabla. Además generará la lista de la compra y tendra un boton para exportarlo a pdf otro para csv y otro mas para generar un nuevo menu mensual. Si usas una api que sea gratuita.
 
 
1
+ Una aplicacion html y javascript en local sin node y con flexbox, que pida recetas bajas en calorias para 30 dias (comida y cena) para personas de mas de 50 años, el menu tiene que ser equilibrado, además tiene que alimentarse de un api de recetas de internet. la aplicacion mostrará la receta, los ingredientes y si es posible de donde las ha sacado, cada comida indicará las calorias en una tabla. Además generará la lista de la compra y tendra un boton para exportarlo a pdf otro para csv y otro mas para generar un nuevo menu mensual. Si usas una api que sea gratuita.
2
+ puedes adaptarlo para usar el api de edamam.com y con mi api key edamam 1b8ad4ca