diff --git a/recipe_scrapers/barefootinthepines.py b/recipe_scrapers/barefootinthepines.py index 611c64150..36190d747 100644 --- a/recipe_scrapers/barefootinthepines.py +++ b/recipe_scrapers/barefootinthepines.py @@ -16,16 +16,41 @@ def ingredient_groups(self): ) def nutrients(self): - nutrition_container = self.soup.select_one(".mv-create-nutrition-box") - if not nutrition_container: + nutrition_section = self.soup.select_one(".mv-create-nutrition-box") + if not nutrition_section: return None - nutrition_data = {} - for item in nutrition_container.select(".mv-create-nutrition-item"): - label = item.select_one(".mv-create-nutrition-label") - if label: - label_text = label.get_text(strip=True) - quantity = item.get_text(strip=True).replace(label_text, "").strip() - nutrition_data[label_text] = quantity + raw_nutrition_data = { + item.select_one(".mv-create-nutrition-label") + .get_text(strip=True) + .lower(): item.get_text(strip=True) + .replace( + item.select_one(".mv-create-nutrition-label").get_text(strip=True), "" + ) + .strip() + for item in nutrition_section.select(".mv-create-nutrition-item") + if item.select_one(".mv-create-nutrition-label") + } - return nutrition_data + nutrition_label_mapping = { + "calories:": "calories", + "carbohydrates:": "carbohydrateContent", + "cholesterol:": "cholesterolContent", + "total fat:": "fatContent", + "fiber:": "fiberContent", + "protein:": "proteinContent", + "saturated fat:": "saturatedFatContent", + "serving size:": "servingSize", + "sodium:": "sodiumContent", + "sugar:": "sugarContent", + "trans fat:": "transFatContent", + "unsaturated fat:": "unsaturatedFatContent", + } + + standardized_nutrition_data = { + schema_label: raw_nutrition_data[custom_label.lower()] + for custom_label, schema_label in nutrition_label_mapping.items() + if custom_label.lower() in raw_nutrition_data + } + + return standardized_nutrition_data diff --git a/tests/test_data/barefootinthepines.com/barefootinthepines_1.json b/tests/test_data/barefootinthepines.com/barefootinthepines_1.json index 0d9953872..81058a5d9 100644 --- a/tests/test_data/barefootinthepines.com/barefootinthepines_1.json +++ b/tests/test_data/barefootinthepines.com/barefootinthepines_1.json @@ -30,19 +30,18 @@ "prep_time": 10, "cuisine": "Side Dishes", "nutrients": { - "Yield:": "4", - "Serving Size:": "1", - "Calories:": "139", - "Total Fat:": "7g", - "Saturated Fat:": "2g", - "Trans Fat:": "0g", - "Unsaturated Fat:": "5g", - "Cholesterol:": "9mg", - "Sodium:": "334mg", - "Carbohydrates:": "15g", - "Fiber:": "3g", - "Sugar:": "8g", - "Protein:": "6g" + "servingSize": "1", + "calories": "139", + "fatContent": "7g", + "saturatedFatContent": "2g", + "unsaturatedFatContent": "5g", + "transFatContent": "0g", + "carbohydrateContent": "15g", + "sugarContent": "8g", + "proteinContent": "6g", + "sodiumContent": "334mg", + "fiberContent": "3g", + "cholesterolContent": "9mg" }, "image": "https://barefootinthepines.com/wp-content/uploads/2024/09/Maple-Bacon-Brussels-Sprouts-4-720x720.jpg", "keywords": [ diff --git a/tests/test_data/barefootinthepines.com/barefootinthepines_2.json b/tests/test_data/barefootinthepines.com/barefootinthepines_2.json index a7bd905cd..e02d728ef 100644 --- a/tests/test_data/barefootinthepines.com/barefootinthepines_2.json +++ b/tests/test_data/barefootinthepines.com/barefootinthepines_2.json @@ -74,19 +74,18 @@ "prep_time": 25, "cuisine": "Thanksgiving Desserts", "nutrients": { - "Yield:": "12", - "Serving Size:": "1 Slice", - "Calories:": "434", - "Total Fat:": "30g", - "Saturated Fat:": "17g", - "Trans Fat:": "0g", - "Unsaturated Fat:": "11g", - "Cholesterol:": "129mg", - "Sodium:": "131mg", - "Carbohydrates:": "41g", - "Fiber:": "2g", - "Sugar:": "30g", - "Protein:": "6g" + "servingSize": "1 Slice", + "calories": "434", + "fatContent": "30g", + "saturatedFatContent": "17g", + "unsaturatedFatContent": "11g", + "transFatContent": "0g", + "carbohydrateContent": "41g", + "sugarContent": "30g", + "proteinContent": "6g", + "sodiumContent": "131mg", + "fiberContent": "2g", + "cholesterolContent": "129mg" }, "image": "https://barefootinthepines.com/wp-content/uploads/2024/09/Chocolate-Pie-With-Graham-Cracker-Crust-7-720x720.jpg", "keywords": [