diff --git a/recipe_scrapers/usdamyplate.py b/recipe_scrapers/usdamyplate.py
index 5ef2c1f55..43e6afc72 100644
--- a/recipe_scrapers/usdamyplate.py
+++ b/recipe_scrapers/usdamyplate.py
@@ -1,6 +1,7 @@
from ._abstract import AbstractScraper
from ._exceptions import StaticValueException
-from ._utils import get_minutes, get_yields, normalize_string
+from ._utils import get_minutes, normalize_string
+from ._grouping_utils import group_ingredients
class USDAMyPlate(AbstractScraper):
@@ -11,49 +12,32 @@ def host(cls):
def site_name(self):
raise StaticValueException(return_value="MyPlate")
- def title(self):
- return self.soup.h1.get_text().strip()
+ def cook_time(self):
+ cook_time_span = self.soup.find(
+ "div", {"class": "mp-recipe-full__detail--cook-time"}
+ ).find("span", {"class": "mp-recipe-full__detail--data"})
- def total_time(self):
- # not in every recipe has time given
- full_detail = self.soup.find(
- "div", {"class": "mp-recipe-full__overview desktop:grid-col-5 grid-row"}
- )
+ if cook_time_span:
+ return get_minutes(cook_time_span)
- minutes = 0
- for span in full_detail.findAll(
- "span", {"class": "mp-recipe-full__detail--data"}
- ):
- if "minute" in span.get_text().lower() or "hour" in span.get_text().lower():
- minutes += get_minutes(span)
+ return 0
- if minutes == 0:
- return None
+ def prep_time(self):
+ prep_time_span = self.soup.find(
+ "div", {"class": "mp-recipe-full__detail--prep-time"}
+ ).find("span", {"class": "mp-recipe-full__detail--data"})
- return minutes
+ if prep_time_span:
+ return get_minutes(prep_time_span)
- def yields(self):
- full_detail = self.soup.find(
- "div", {"class": "mp-recipe-full__overview desktop:grid-col-5 grid-row"}
- )
+ return 0
- spans = full_detail.findAll("span")
- i = 0
- for span in spans:
- if "Makes:" in span:
- return get_yields(spans[i + 1])
- i += 1
+ def total_time(self):
+ cook_time = self.cook_time()
+ prep_time = self.prep_time()
- def image(self):
- div = self.soup.find(
- "div",
- {
- "class": "field field--name-field-recipe-image field--type-image field--label-visually_hidden"
- },
- )
- url = div.find("img")["src"]
- # return only the portion before the question mark
- return url.split("?")[0]
+ total_minutes = cook_time + prep_time
+ return total_minutes
def ingredients(self):
ingredients = self.soup.find(
@@ -62,6 +46,17 @@ def ingredients(self):
return [normalize_string(paragraph.get_text()) for paragraph in ingredients]
+ def ingredient_groups(self):
+ ingredients_section = self.soup.find(
+ "div", {"class": "field--name-field-ingredients"}
+ )
+ return group_ingredients(
+ self.ingredients(),
+ ingredients_section,
+ "b",
+ "li.field__item",
+ )
+
def instructions(self):
div = self.soup.find(
"div",
@@ -92,24 +87,3 @@ def nutrients(self):
nutrition[el[0]] = el[1]
return nutrition
-
- def serving_size(self):
- return normalize_string(
- self.soup.find("div", {"class": "field--name-field-recipe-serving-size"})
- .find("span", {"class": "field__item"})
- .get_text()
- )
-
- def description(self):
- return normalize_string(
- self.soup.find("div", {"class": "mp-recipe-full__description"})
- .find("p")
- .get_text()
- )
-
- def recipe_source(self):
- return normalize_string(
- self.soup.find("span", {"class": "field--name-field-source"})
- .find("p")
- .get_text()
- )
diff --git a/tests/test_data/myplate.gov/usdamyplate.json b/tests/test_data/myplate.gov/usdamyplate_1.json
similarity index 88%
rename from tests/test_data/myplate.gov/usdamyplate.json
rename to tests/test_data/myplate.gov/usdamyplate_1.json
index dd8e04bd0..d65e49d1a 100644
--- a/tests/test_data/myplate.gov/usdamyplate.json
+++ b/tests/test_data/myplate.gov/usdamyplate_1.json
@@ -1,6 +1,6 @@
{
"author": "MyPlate",
- "canonical_url": "https://www.myplate.gov/recipes/supplemental-nutrition-assistance-program-snap/fabulous-fig-bars",
+ "canonical_url": "https://www.myplate.gov/recipes/fabulous-fig-bars",
"site_name": "MyPlate",
"host": "myplate.gov",
"language": "en",
@@ -28,12 +28,11 @@
"Spread fig mixture evenly over the dough. Crumble reserved dough over top, allowing fig mixture to show.",
"Bake 30 minutes or until golden brown. Cool completely in baking pan. Cut into 24 bars (about 2 1/2 x 2 inches)."
],
- "category": null,
- "yields": "24 bars",
+ "yields": "24 servings",
"description": "Fig bars are a great on-the-go snack. The sweet, nutty flavors in these bars are sure to be a hit with all ages.",
"total_time": 75,
- "cook_time": 1,
- "prep_time": 1,
+ "cook_time": 30,
+ "prep_time": 45,
"ratings": 3.44,
"ratings_count": 9,
"nutrients": {
@@ -52,5 +51,5 @@
"Iron": "1 mg",
"Potassium": "169 mg"
},
- "image": "https://myplate-prod.azureedge.us/sites/default/files/styles/recipe_525_x_350_/public/2021-03/FigBars.jpg"
+ "image": "https://myplate-prod.azureedge.us/sites/default/files/styles/medium/public/2021-03/FigBars.jpg?itok=3ZW7jyGj"
}
diff --git a/tests/test_data/myplate.gov/usdamyplate.testhtml b/tests/test_data/myplate.gov/usdamyplate_1.testhtml
similarity index 72%
rename from tests/test_data/myplate.gov/usdamyplate.testhtml
rename to tests/test_data/myplate.gov/usdamyplate_1.testhtml
index 3e5d7d9cc..9e736f16f 100644
--- a/tests/test_data/myplate.gov/usdamyplate.testhtml
+++ b/tests/test_data/myplate.gov/usdamyplate_1.testhtml
@@ -1,2298 +1,2393 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Fabulous Fig Bars | MyPlate
-
-
-
-
-
-
-
-
-
-
-
-
-
- Skip to main content
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- The .gov means it’s official.
-
-
- Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.
-
-
-
-
-
-
-
- The site is secure.
-
-
- The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Fabulous Fig Bars
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Add to cookbook
-
-
-
-
-
-
Recipe Image
-
-
-
-
-
-
-
-
-
-
-
- Makes:
-
- 24
-
- Bars
-
-
-
-
-
-
- Total Cost:
-
- $ $ $ $
-
-
-
-
-
- Cook Time:
- 30 minutes
-
-
-
-
- Preparation Time:
- 45 minutes
-
-
-
-
-
-
-
-
Fig bars are a great on-the-go snack. The sweet, nutty flavors in these bars are sure to be a hit with all ages.
-
-
-
-
-
-
-
-
Ingredients
-
-
-
- 2
-
-
-
- cups
-
-
-
-
-
- dried figs
-
-
- (chopped, 16 ounces)
-
-
-
-
-
- 1/2
-
-
-
- cup
-
-
-
-
-
- walnuts
-
-
- (chopped)
-
-
-
-
-
- 1/3
-
-
-
- cup
-
-
-
-
-
- sugar
-
-
-
-
-
-
-
- 1/4
-
-
-
- cup
-
-
-
-
-
- orange juice
-
-
- (juice from 1/2 orange)
-
-
-
-
-
- 2
-
-
-
- tablespoons
-
-
-
-
-
- hot water
-
-
-
-
-
-
-
- 1/2
-
-
-
- cup
-
-
-
-
-
- margarine
-
-
- (softened, or butter)
-
-
-
-
-
- 1
-
-
-
- cup
-
-
-
-
-
- packed brown sugar
-
-
-
-
-
-
-
- 1
-
-
-
-
-
-
-
- large egg
-
-
-
-
-
-
-
- 1 1/2
-
-
-
- cups
-
-
-
-
-
- all-purpose flour
-
-
-
-
-
-
-
- 1/2
-
-
-
- teaspoon
-
-
-
-
-
- baking soda
-
-
-
-
-
-
-
- 1 1/4
-
-
-
- cups
-
-
-
-
-
- old fashioned rolled oats
-
-
-
-
-
-
-
-
-
-
-
Directions
-
Wash hands with soap and water.
- Preheat oven to 350 °F. Lightly grease a 9x13 inch baking pan.
- Combine figs, walnuts, sugar, orange juice, and hot water in a mixing bowl and set aside.
- Mix together margarine or butter and brown sugar until creamy. Add egg and mix until smooth.
- Mix flour and baking soda. Stir into egg mixture. Blend in oats to make soft dough.
- Reserve 1 cup of dough for topping. With floured fingertips, press the remaining dough into a thin layer on the bottom of the baking pan.
- Spread fig mixture evenly over the dough. Crumble reserved dough over top, allowing fig mixture to show.
- Bake 30 minutes or until golden brown. Cool completely in baking pan. Cut into 24 bars (about 2 1/2 x 2 inches).
-
-
-
-
-
-
Notes
-
No dried figs? Use 3 cups chopped fresh figs. Omit the hot water and orange juice, but add 1 teaspoon lemon or orange zest (grate the outer colored part of the peel).
- Margarine used for nutrition and cost analysis.
-
-
-
-
-
-
- Source:
- Food Hero
-Oregon State University Cooperative Extension Service
-
-
-
-
-
-
-
-
-
- Nutrition Information
-
-
-
- Serving Size:
-
- 1 bar
-
-
-
-
-
-
-
-
-
-
-
- MyPlate Food Groups
-
-
-
-
-
- Fruits
- 1/4 cups
-
-
-
- Grains
- 1/2 ounces
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Fabulous Fig Bars | MyPlate
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Skip to main content
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The .gov means it’s official.
+
+
+ Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.
+
+
+
+
+
+
+
+ The site is secure.
+
+
+ The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Fabulous Fig Bars
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Add to cookbook
+
+
+
+
+
+
Recipe Image
+
+
+
+
+
+
+
+
+
+
+
+ Makes:
+
+ 24
+
+ Bars
+
+
+
+
+
+
+ Total Cost:
+
+ $ $ $ $
+
+
+
+
+
+ Cook Time:
+ 30 minutes
+
+
+
+
+ Preparation Time:
+ 45 minutes
+
+
+
+
+
+
+
+
Fig bars are a great on-the-go snack. The sweet, nutty flavors in these bars are sure to be a hit with all ages.
+
+
+
+
+
+
+
+
Ingredients
+
+
+
+ 2
+
+
+
+ cups
+
+
+
+
+
+ dried figs
+
+
+ (chopped, 16 ounces)
+
+
+
+
+
+ 1/2
+
+
+
+ cup
+
+
+
+
+
+ walnuts
+
+
+ (chopped)
+
+
+
+
+
+ 1/3
+
+
+
+ cup
+
+
+
+
+
+ sugar
+
+
+
+
+
+
+
+ 1/4
+
+
+
+ cup
+
+
+
+
+
+ orange juice
+
+
+ (juice from 1/2 orange)
+
+
+
+
+
+ 2
+
+
+
+ tablespoons
+
+
+
+
+
+ hot water
+
+
+
+
+
+
+
+ 1/2
+
+
+
+ cup
+
+
+
+
+
+ margarine
+
+
+ (softened, or butter)
+
+
+
+
+
+ 1
+
+
+
+ cup
+
+
+
+
+
+ packed brown sugar
+
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+
+ large egg
+
+
+
+
+
+
+
+ 1 1/2
+
+
+
+ cups
+
+
+
+
+
+ all-purpose flour
+
+
+
+
+
+
+
+ 1/2
+
+
+
+ teaspoon
+
+
+
+
+
+ baking soda
+
+
+
+
+
+
+
+ 1 1/4
+
+
+
+ cups
+
+
+
+
+
+ old fashioned rolled oats
+
+
+
+
+
+
+
+
+
+
+
Directions
+
+ Wash hands with soap and water.
+ Preheat oven to 350 °F. Lightly grease a 9x13 inch baking pan.
+ Combine figs, walnuts, sugar, orange juice, and hot water in a mixing bowl and set aside.
+ Mix together margarine or butter and brown sugar until creamy. Add egg and mix until smooth.
+ Mix flour and baking soda. Stir into egg mixture. Blend in oats to make soft dough.
+ Reserve 1 cup of dough for topping. With floured fingertips, press the remaining dough into a thin layer on the bottom of the baking pan.
+ Spread fig mixture evenly over the dough. Crumble reserved dough over top, allowing fig mixture to show.
+ Bake 30 minutes or until golden brown. Cool completely in baking pan. Cut into 24 bars (about 2 1/2 x 2 inches).
+
+
+
+
+
+
+
Notes
+
+ No dried figs? Use 3 cups chopped fresh figs. Omit the hot water and orange juice, but add 1 teaspoon lemon or orange zest (grate the outer colored part of the peel).
+ Margarine used for nutrition and cost analysis.
+
+
+
+
+
+
+
+ Source:
+ Food Hero
+Oregon State University Cooperative Extension Service
+
+
+
+
+
+
+
+
+
+
+ Nutrition Information
+
+
+
+ Serving Size:
+
+ 1 bar
+
+
+
+
+
+
+
+
+
+
+
+ MyPlate Food Groups
+
+
+
+
+
+ Fruits
+ 1/4 cups
+
+
+
+ Grains
+ 1/2 ounces
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/test_data/myplate.gov/usdamyplate_2.json b/tests/test_data/myplate.gov/usdamyplate_2.json
new file mode 100644
index 000000000..e4d0dc28f
--- /dev/null
+++ b/tests/test_data/myplate.gov/usdamyplate_2.json
@@ -0,0 +1,68 @@
+{
+ "author": "MyPlate",
+ "canonical_url": "https://www.myplate.gov/recipes/asparagus-mandarin-orange-chicken-and-rice",
+ "site_name": "MyPlate",
+ "host": "myplate.gov",
+ "language": "en",
+ "title": "Asparagus, Mandarin Orange, Chicken, and Rice",
+ "ingredients": [
+ "2 tablespoons extra virgin olive oil",
+ "2 tablespoons rice vinegar",
+ "3 tablespoons mandarin orange juice (reserved from oranges)",
+ "1 tablespoon soy sauce, reduced sodium",
+ "3 1/3 cups fresh asparagus (trimmed)",
+ "2 cans 11 oz cans mandarin oranges (drained, reserve juice)",
+ "12 ounces cooked chicken breast (cut into chunks)",
+ "3 cups cooked instant brown rice"
+ ],
+ "ingredient_groups": [
+ {
+ "ingredients": [
+ "2 tablespoons extra virgin olive oil",
+ "2 tablespoons rice vinegar",
+ "3 tablespoons mandarin orange juice (reserved from oranges)",
+ "1 tablespoon soy sauce, reduced sodium"
+ ],
+ "purpose": "For the Vinaigrette:"
+ },
+ {
+ "ingredients": [
+ "3 1/3 cups fresh asparagus (trimmed)",
+ "2 cans 11 oz cans mandarin oranges (drained, reserve juice)",
+ "12 ounces cooked chicken breast (cut into chunks)",
+ "3 cups cooked instant brown rice"
+ ],
+ "purpose": "For the Salad:"
+ }
+ ],
+ "instructions_list": [
+ "In a small bowl, whisk vinaigrette ingredients, set aside.",
+ "Cook rice according to package directions.",
+ "Place whole trimmed asparagus in a large skillet with 1 1/2 inches of water.",
+ "Bring to a boil, reduce heat and simmer, uncovered, for 2-5 minutes.",
+ "Rinse with cool water and cut into 1-inch pieces.",
+ "In a medium size bowl, toss all ingredients."
+ ],
+ "yields": "4 servings",
+ "description": "Fresh California asparagus, mandarin oranges, chicken, and brown rice make perfect compliments in this Asian-influenced salad.",
+ "prep_time": 30,
+ "ratings": 3.46,
+ "ratings_count": 164,
+ "nutrients": {
+ "Total Calories": "440",
+ "Total Fat": "11 g",
+ "Saturated Fat": "2 g",
+ "Cholesterol": "70 mg",
+ "Sodium": "N/A",
+ "Carbohydrates": "51 g",
+ "Dietary Fiber": "6 g",
+ "Total Sugars": "12 g",
+ "Added Sugars included": "0 g",
+ "Protein": "33 g",
+ "Vitamin D": "0 mcg",
+ "Calcium": "63 mg",
+ "Iron": "3 mg",
+ "Potassium": "737 mg"
+ },
+ "image": "https://myplate-prod.azureedge.us/sites/default/files/styles/medium/public/recipe-images/Asparagus%20Manderin%20Salad.jpg?itok=Kpd19Hqu"
+}
diff --git a/tests/test_data/myplate.gov/usdamyplate_2.testhtml b/tests/test_data/myplate.gov/usdamyplate_2.testhtml
new file mode 100644
index 000000000..db18d654c
--- /dev/null
+++ b/tests/test_data/myplate.gov/usdamyplate_2.testhtml
@@ -0,0 +1,2278 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Asparagus, Mandarin Orange, Chicken, and Rice | MyPlate
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Skip to main content
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The .gov means it’s official.
+
+
+ Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.
+
+
+
+
+
+
+
+ The site is secure.
+
+
+ The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Asparagus, Mandarin Orange, Chicken, and Rice
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Add to cookbook
+
+
+
+
+
+
Recipe Image
+
+
+
+
+
+
+
+
+
+
+
+ Makes:
+
+ 4
+
+ Servings
+
+
+
+
+
+
+ Total Cost:
+
+ $ $ $ $
+
+
+
+
+
+
+ Preparation Time:
+ 30 minutes
+
+
+
+
+
+
+
+
Fresh California asparagus, mandarin oranges, chicken, and brown rice make perfect compliments in this Asian-influenced salad.
+
+
+
+
+
+
+
+
Ingredients
+
+
+ For the Vinaigrette:
+
+
+
+
+
+
+ 2
+
+
+
+ tablespoons
+
+
+
+
+
+ extra virgin olive oil
+
+
+
+
+
+
+
+ 2
+
+
+
+ tablespoons
+
+
+
+
+
+ rice vinegar
+
+
+
+
+
+
+
+ 3
+
+
+
+ tablespoons
+
+
+
+
+
+ mandarin orange juice
+
+
+ (reserved from oranges)
+
+
+
+
+
+ 1
+
+
+
+ tablespoon
+
+
+
+
+
+ soy sauce, reduced sodium
+
+
+
+
+
+
+
+ For the Salad:
+
+
+
+
+
+
+ 3 1/3
+
+
+
+ cups
+
+
+
+
+
+ fresh asparagus
+
+
+ (trimmed)
+
+
+
+
+
+ 2
+
+
+
+ cans
+
+
+
+
+
+ 11 oz cans mandarin oranges
+
+
+ (drained, reserve juice)
+
+
+
+
+
+ 12
+
+
+
+ ounces
+
+
+
+
+
+ cooked chicken breast
+
+
+ (cut into chunks)
+
+
+
+
+
+ 3
+
+
+
+ cups
+
+
+
+
+
+ cooked instant brown rice
+
+
+
+
+
+
+
+
+
+
+
Directions
+
+ In a small bowl, whisk vinaigrette ingredients, set aside.
+ Cook rice according to package directions.
+ Place whole trimmed asparagus in a large skillet with 1 1/2 inches of water.
+ Bring to a boil, reduce heat and simmer, uncovered, for 2-5 minutes.
+ Rinse with cool water and cut into 1-inch pieces.
+ In a medium size bowl, toss all ingredients.
+
+
+
+
+
+
+
Notes
+
Weekly Meal Planning Tip: When you're planning a dinner with chicken, cook up extra chicken breast and refrigerate for later use in this salad.
+
+
Learn more about:
+
+
+
+
+
+
+
+
+ Source:
+ Produce for Better Health Foundation
+
+
+
+
+
+
+
+
+
+ Nutrition Information
+
+
+
+
+
+
+
+
+
+
+ MyPlate Food Groups
+
+
+
+
+
+ Fruits
+ 3/4 cups
+
+
+
+ Vegetables
+ 1/2 cups
+
+
+
+ Grains
+ 1 1/2 ounces
+
+
+
+ Protein Foods
+ 3 ounces
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+