bar
Some checks are pending
Python lint and test / linttest (push) Waiting to run

This commit is contained in:
Piotr Domański 2026-04-02 11:45:06 +02:00
parent 37af9f3943
commit 8b25182645

View file

@ -36,16 +36,18 @@ def find(bar_code: str) -> Product:
name = data["product"]["product_name"]
if data["product"]["brands"]:
name = data["product"]["brands"] + " " + name
brands = data["product"].get("brands")
if brands:
name = brands + " " + name
nutriments = data["product"]["nutriments"]
return Product(
name=name,
kcal=data["product"]["nutriments"]["energy-kcal_100g"],
fat=data["product"]["nutriments"]["fat_100g"],
protein=data["product"]["nutriments"]["proteins_100g"],
carb=data["product"]["nutriments"]["carbohydrates_100g"],
fiber=data["product"]["nutriments"].get("fiber_100g", 0.0),
kcal=nutriments.get("energy-kcal_100g") or 0.0,
fat=nutriments.get("fat_100g") or 0.0,
protein=nutriments.get("proteins_100g") or 0.0,
carb=nutriments.get("carbohydrates_100g") or 0.0,
fiber=nutriments.get("fiber_100g") or 0.0,
)
except Exception as e:
logger.error(e)