mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-14 11:53:11 -05:00
feat: adding the rest ofthe nutrition properties from schema.org (#4301)
This commit is contained in:
@@ -37,6 +37,19 @@ def get_value_as_string_or_none(dictionary: dict, key: str):
|
||||
return None
|
||||
|
||||
|
||||
nutrition_map = {
|
||||
"Calories": "calories",
|
||||
"Fat": "fatContent",
|
||||
"Saturated Fat": "saturatedFatContent",
|
||||
"Cholesterol": "cholesterolContent",
|
||||
"Sodium": "sodiumContent",
|
||||
"Sugar": "sugarContent",
|
||||
"Carbohydrate": "carbohydrateContent",
|
||||
"Fiber": "fiberContent",
|
||||
"Protein": "proteinContent",
|
||||
}
|
||||
|
||||
|
||||
class PlanToEatMigrator(BaseMigrator):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -63,16 +76,7 @@ class PlanToEatMigrator(BaseMigrator):
|
||||
|
||||
def _parse_recipe_nutrition_from_row(self, row: dict) -> dict:
|
||||
"""Parses the nutrition data from the row"""
|
||||
|
||||
nut_dict: dict = {}
|
||||
|
||||
nut_dict["calories"] = get_value_as_string_or_none(row, "Calories")
|
||||
nut_dict["fatContent"] = get_value_as_string_or_none(row, "Fat")
|
||||
nut_dict["proteinContent"] = get_value_as_string_or_none(row, "Protein")
|
||||
nut_dict["carbohydrateContent"] = get_value_as_string_or_none(row, "Carbohydrate")
|
||||
nut_dict["fiberContent"] = get_value_as_string_or_none(row, "Fiber")
|
||||
nut_dict["sodiumContent"] = get_value_as_string_or_none(row, "Sodium")
|
||||
nut_dict["sugarContent"] = get_value_as_string_or_none(row, "Sugar")
|
||||
nut_dict = {normalized_k: row[k] for k, normalized_k in nutrition_map.items() if k in row}
|
||||
|
||||
return cleaner.clean_nutrition(nut_dict)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user