note7 commited on
Commit
5ba2bdd
·
verified ·
1 Parent(s): 19817be

Add 2 files

Browse files
Files changed (2) hide show
  1. index.html +77 -52
  2. prompts.txt +2 -1
index.html CHANGED
@@ -484,6 +484,7 @@
484
  .instructions-text {
485
  font-size: 0.9rem;
486
  color: #4a5568;
 
487
  }
488
 
489
  .recipe-source {
@@ -755,10 +756,8 @@
755
  </div>
756
 
757
  <script>
758
- // API Configuration for Edamam
759
- const APP_ID = '792809ad'; // Reemplaza con tu App ID de Edamam
760
- const APP_KEY = 'c56f43e41803a04bf7506ecd87db5a1f'; // Reemplaza con tu App Key de Edamam
761
- const API_URL = 'https://api.edamam.com/api/recipes/v2';
762
 
763
  // Global variables
764
  let currentMenu = [];
@@ -875,64 +874,90 @@
875
  }
876
  }
877
 
878
- // Fetch healthy recipe from Edamam API
879
  async function fetchHealthyRecipe(mealType) {
880
- const maxCalories = mealType === 'breakfast' ? 400 :
881
- mealType === 'lunch' ? 600 : 500;
882
- const minProtein = mealType === 'breakfast' ? 10 :
883
- mealType === 'lunch' ? 25 : 15;
884
-
885
- // Parámetros de búsqueda para Edamam
886
- const searchParams = new URLSearchParams({
887
- type: 'public',
888
- app_id: APP_ID,
889
- app_key: APP_KEY,
890
- mealType: mealType,
891
- calories: `0-${maxCalories}`,
892
- health: 'vegetarian,gluten-free', // Puedes ajustar según necesidades
893
- diet: 'balanced', // Puedes ajustar según necesidades
894
- random: 'true'
895
- });
896
-
897
- const url = `${API_URL}?${searchParams}`;
898
-
899
  try {
900
- // Buscar recetas en Edamam con los headers solicitados
901
- const response = await fetch(url, {
902
- method: 'GET',
903
- headers: {
904
- 'accept': 'application/json',
905
- 'Edamam-Account-User': 'note',
906
- 'Accept-Language': 'es'
907
- }
908
- });
909
 
910
- const data = await response.json();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
911
 
912
- if (data.hits.length === 0) {
913
  console.warn(`No recipes found for ${mealType}`);
914
  return null;
915
  }
916
 
917
- // Tomamos la primera receta de los resultados
918
- const recipeData = data.hits[0].recipe;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
919
 
920
- // Formateamos los datos de la receta para nuestra app
921
  return {
922
- id: recipeData.uri.split('#')[1], // Extraemos el ID de la URI
923
- title: recipeData.label,
924
- image: recipeData.image || 'https://via.placeholder.com/400x300?text=Imagen+no+disponible',
925
- servings: recipeData.yield || 2,
926
- sourceUrl: recipeData.url,
927
- sourceName: recipeData.source || 'Edamam',
928
- ingredients: recipeData.ingredients || [],
929
- instructions: recipeData.instructions || 'Ver instrucciones en el enlace original',
930
  nutrition: {
931
- calories: Math.round(recipeData.calories / (recipeData.yield || 1)),
932
- protein: Math.round(recipeData.totalNutrients.PROCNT.quantity / (recipeData.yield || 1)),
933
- carbs: Math.round(recipeData.totalNutrients.CHOCDF.quantity / (recipeData.yield || 1)),
934
- fat: Math.round(recipeData.totalNutrients.FAT.quantity / (recipeData.yield || 1)),
935
- fiber: Math.round(recipeData.totalNutrients.FIBTG.quantity / (recipeData.yield || 1))
936
  }
937
  };
938
  } catch (error) {
@@ -945,7 +970,7 @@
945
  function addToShoppingList(ingredients) {
946
  ingredients.forEach(ingredient => {
947
  const name = ingredient.food.toLowerCase();
948
- const amount = ingredient.quantity || 1;
949
  const unit = ingredient.measure || 'unidad';
950
 
951
  if (shoppingList[name]) {
 
484
  .instructions-text {
485
  font-size: 0.9rem;
486
  color: #4a5568;
487
+ white-space: pre-line;
488
  }
489
 
490
  .recipe-source {
 
756
  </div>
757
 
758
  <script>
759
+ // API Configuration for TheMealDB
760
+ const API_URL = 'https://www.themealdb.com/api/json/v1/1/';
 
 
761
 
762
  // Global variables
763
  let currentMenu = [];
 
874
  }
875
  }
876
 
877
+ // Fetch healthy recipe from TheMealDB API
878
  async function fetchHealthyRecipe(mealType) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
879
  try {
880
+ let endpoint;
 
 
 
 
 
 
 
 
881
 
882
+ // TheMealDB doesn't have meal types, so we'll use categories
883
+ if (mealType === 'breakfast') {
884
+ // For breakfast, we'll use "Breakfast" category or similar
885
+ endpoint = 'filter.php?c=Breakfast';
886
+ } else if (mealType === 'lunch') {
887
+ // For lunch, we'll use "Vegetarian" or "Chicken" categories
888
+ endpoint = 'filter.php?c=Vegetarian';
889
+ } else {
890
+ // For dinner, we'll use "Seafood" or "Pasta" categories
891
+ endpoint = 'filter.php?c=Seafood';
892
+ }
893
+
894
+ // First fetch a list of meals
895
+ const listResponse = await fetch(`${API_URL}${endpoint}`);
896
+ const listData = await listResponse.json();
897
 
898
+ if (!listData.meals || listData.meals.length === 0) {
899
  console.warn(`No recipes found for ${mealType}`);
900
  return null;
901
  }
902
 
903
+ // Select a random meal from the list
904
+ const randomIndex = Math.floor(Math.random() * listData.meals.length);
905
+ const mealId = listData.meals[randomIndex].idMeal;
906
+
907
+ // Then fetch the full details of that meal
908
+ const detailResponse = await fetch(`${API_URL}lookup.php?i=${mealId}`);
909
+ const detailData = await detailResponse.json();
910
+
911
+ if (!detailData.meals || detailData.meals.length === 0) {
912
+ return null;
913
+ }
914
+
915
+ const meal = detailData.meals[0];
916
+
917
+ // Extract ingredients and measures
918
+ const ingredients = [];
919
+ for (let i = 1; i <= 20; i++) {
920
+ const ingredient = meal[`strIngredient${i}`];
921
+ const measure = meal[`strMeasure${i}`];
922
+
923
+ if (ingredient && ingredient.trim() !== '') {
924
+ ingredients.push({
925
+ food: ingredient,
926
+ measure: measure || '',
927
+ text: `${measure || ''} ${ingredient}`.trim()
928
+ });
929
+ }
930
+ }
931
+
932
+ // Estimate nutrition (TheMealDB doesn't provide nutrition info)
933
+ // We'll use some averages based on meal type
934
+ let calories, protein;
935
+ if (mealType === 'breakfast') {
936
+ calories = 300 + Math.floor(Math.random() * 200); // 300-500 kcal
937
+ protein = 10 + Math.floor(Math.random() * 10); // 10-20g
938
+ } else if (mealType === 'lunch') {
939
+ calories = 500 + Math.floor(Math.random() * 300); // 500-800 kcal
940
+ protein = 20 + Math.floor(Math.random() * 15); // 20-35g
941
+ } else {
942
+ calories = 400 + Math.floor(Math.random() * 300); // 400-700 kcal
943
+ protein = 15 + Math.floor(Math.random() * 15); // 15-30g
944
+ }
945
 
 
946
  return {
947
+ id: meal.idMeal,
948
+ title: meal.strMeal,
949
+ image: meal.strMealThumb || 'https://via.placeholder.com/400x300?text=Imagen+no+disponible',
950
+ servings: 2, // Default to 2 servings
951
+ sourceUrl: meal.strSource || meal.strYoutube || '#',
952
+ sourceName: meal.strArea || 'TheMealDB',
953
+ ingredients: ingredients,
954
+ instructions: meal.strInstructions || 'Ver instrucciones en el enlace original',
955
  nutrition: {
956
+ calories: calories,
957
+ protein: protein,
958
+ carbs: Math.round(calories * 0.4 / 4), // 40% carbs
959
+ fat: Math.round(calories * 0.3 / 9), // 30% fat
960
+ fiber: 5 + Math.floor(Math.random() * 10) // 5-15g fiber
961
  }
962
  };
963
  } catch (error) {
 
970
  function addToShoppingList(ingredients) {
971
  ingredients.forEach(ingredient => {
972
  const name = ingredient.food.toLowerCase();
973
+ const amount = 1; // Default to 1 unit since we don't have precise measures
974
  const unit = ingredient.measure || 'unidad';
975
 
976
  if (shoppingList[name]) {
prompts.txt CHANGED
@@ -4,4 +4,5 @@ puedes hacerlo con flexbox y arreglar el siguiente error:
4
  NO USES tailwind USA FLEXBOX
5
  puedes adaptarla para usar spoonacular api?
6
  puedes usar edamam como api?
7
- puedes hacer que las comidas sean cenas y comidas. modifica para que use const response = await fetch(url, { method: 'GET', headers: { 'accept': 'application/json', 'Edamam-Account-User': 'note', 'Accept-Language': 'es' } }); ademas NO USES TAILWIND, USA FLEXBOX
 
 
4
  NO USES tailwind USA FLEXBOX
5
  puedes adaptarla para usar spoonacular api?
6
  puedes usar edamam como api?
7
+ puedes hacer que las comidas sean cenas y comidas. modifica para que use const response = await fetch(url, { method: 'GET', headers: { 'accept': 'application/json', 'Edamam-Account-User': 'note', 'Accept-Language': 'es' } }); ademas NO USES TAILWIND, USA FLEXBOX
8
+ puedes hacer lo mismo pero usando la api de themealdb.com