import requests from scipy.optimize import linprog # --- 1ïžâƒŁ Fonction pour rĂ©cupĂ©rer les donnĂ©es via OpenFoodFacts --- def get_aliment_par_codebarre(barcode): url = f"https://world.openfoodfacts.org/api/v0/product/{barcode}.json" r = requests.get(url) data = r.json() if data.get("status") == 1: product = data["product"] nutriments = product.get("nutriments", {}) return { "nom": product.get("product_name", "Inconnu"), "proteines": nutriments.get("proteins_100g", 0), "glucides": nutriments.get("carbohydrates_100g", 0), "lipides": nutriments.get("fat_100g", 0) } else: print(f"❌ Produit non trouvĂ© pour le code-barres {barcode}") return None # --- 2ïžâƒŁ Entrer les macros restantes --- proteines_restantes = float(input("Proteines restantes (g) : ")) glucides_restantes = float(input("Glucides restantes (g) : ")) lipides_restantes = float(input("Lipides restantes (g) : ")) # --- 3ïžâƒŁ Scanner / entrer les codes-barres des aliments --- aliments_choisis = [] for i in range(3): barcode = input(f"Code-barres de l'aliment {i+1} : ") aliment = get_aliment_par_codebarre(barcode) if aliment: aliments_choisis.append(aliment) # --- 4ïžâƒŁ VĂ©rifier qu'on a au moins 2-3 aliments valides --- if len(aliments_choisis) < 2: print("❌ Il faut au moins 2 aliments valides pour calculer.") exit() # --- 5ïžâƒŁ PrĂ©parer les coefficients pour linprog --- P = [a["proteines"]/100 for a in aliments_choisis] G = [a["glucides"]/100 for a in aliments_choisis] L = [a["lipides"]/100 for a in aliments_choisis] c = [1]*len(aliments_choisis) A_eq = [P, G, L] b_eq = [proteines_restantes, glucides_restantes, lipides_restantes] bounds = [(0, None)]*len(aliments_choisis) # --- 6ïžâƒŁ RĂ©soudre le systĂšme --- res = linprog(c, A_eq=A_eq, b_eq=b_eq, bounds=bounds, method="highs") # --- 7ïžâƒŁ Afficher le rĂ©sultat --- if res.success: print("\n✅ QuantitĂ©s exactes pour couvrir tes macros restantes :") for i, a in enumerate(aliments_choisis): print(f"- {a['nom']} : {res.x[i]:.0f} g") else: print("\n❌ Impossible de rĂ©soudre le calcul avec ces aliments.")
NOTRE BOUTIQUE

Horaires

 

Lundi au Vendredi 9:00 - 12:00 14:00 - 18:00
Samedi et Dimanche Fermé  

 

17 Avenue des Gençeaux

26120 Montmeyran