From bbeddff50ed0444740a10565305c455287709cf6 Mon Sep 17 00:00:00 2001 From: Jacob Rasmussen <2988654+jacrasmussen@users.noreply.github.com> Date: Sat, 15 Feb 2025 23:50:12 +0100 Subject: [PATCH] Refactor nutrient formatting --- recipe_scrapers/spisbedre.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/recipe_scrapers/spisbedre.py b/recipe_scrapers/spisbedre.py index 8acf6007f..8cf4ad34c 100644 --- a/recipe_scrapers/spisbedre.py +++ b/recipe_scrapers/spisbedre.py @@ -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"), }