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"]
|
name = data["product"]["product_name"]
|
||||||
|
|
||||||
if data["product"]["brands"]:
|
brands = data["product"].get("brands")
|
||||||
name = data["product"]["brands"] + " " + name
|
if brands:
|
||||||
|
name = brands + " " + name
|
||||||
|
|
||||||
|
nutriments = data["product"]["nutriments"]
|
||||||
return Product(
|
return Product(
|
||||||
name=name,
|
name=name,
|
||||||
kcal=data["product"]["nutriments"]["energy-kcal_100g"],
|
kcal=nutriments.get("energy-kcal_100g") or 0.0,
|
||||||
fat=data["product"]["nutriments"]["fat_100g"],
|
fat=nutriments.get("fat_100g") or 0.0,
|
||||||
protein=data["product"]["nutriments"]["proteins_100g"],
|
protein=nutriments.get("proteins_100g") or 0.0,
|
||||||
carb=data["product"]["nutriments"]["carbohydrates_100g"],
|
carb=nutriments.get("carbohydrates_100g") or 0.0,
|
||||||
fiber=data["product"]["nutriments"].get("fiber_100g", 0.0),
|
fiber=nutriments.get("fiber_100g") or 0.0,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue