This commit is contained in:
parent
37af9f3943
commit
8b25182645
1 changed files with 9 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue