Skip to content

Commit

Permalink
Refactor nutrient formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jacrasmussen committed Feb 15, 2025
1 parent 4bb903f commit bbeddff
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions recipe_scrapers/spisbedre.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,12 @@ def nutrients(self):
if not nutrition:
return None

calories = round(nutrition.get("calories"))
fat = round(nutrition.get("fat"))
carbohydrates = round(nutrition.get("carbohydrates"))
protein = round(nutrition.get("protein"))
def format_nutrient(value, unit):
return f"{round(value)} {unit}"

return {
"calories": f"{calories} kcal",
"fatContent": f"{fat} g",
"carbohydrateContent": f"{carbohydrates} g",
"proteinContent": f"{protein} g",
"calories": format_nutrient(nutrition.get("calories"), "kcal"),
"fatContent": format_nutrient(nutrition.get("fat"), "g"),
"carbohydrateContent": format_nutrient(nutrition.get("carbohydrates"), "g"),
"proteinContent": format_nutrient(nutrition.get("protein"), "g"),
}

0 comments on commit bbeddff

Please sign in to comment.