Skip to content

Commit

Permalink
Ingredient grouping support for usapears (#1284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jknndy authored Oct 17, 2024
1 parent ec92b83 commit a648c1a
Show file tree
Hide file tree
Showing 5 changed files with 1,182 additions and 42 deletions.
13 changes: 12 additions & 1 deletion recipe_scrapers/usapears.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ._abstract import AbstractScraper
from ._exceptions import ElementNotFoundInHtml
from ._grouping_utils import group_ingredients
from ._utils import get_minutes, normalize_string


Expand All @@ -21,13 +22,23 @@ def total_time(self):
return total_time

def ingredients(self):
ingredient_elements = self.soup.find_all("li", {"itemprop": "ingredients"})
ingredient_elements = self.soup.select(
'li[itemprop="ingredients"]:not(:has(strong))'
)

return [
normalize_string(paragraph.get_text().strip())
for paragraph in ingredient_elements
]

def ingredient_groups(self):
return group_ingredients(
self.ingredients(),
self.soup,
'li[itemprop="ingredients"] strong',
'li[itemprop="ingredients"]:not(:has(strong))',
)

def nutrients(self):
container = self.soup.find("ul", {"itemprop": "nutrition"})
if not container:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'></script>
<![endif]-->

<meta property="og:title" content="Sauteed Bosc Pears" />
<meta property="og:description" content="This simple, tasty pear recipe was created by Chef Jamie Lauren of Absinthe Brasserie and Bar in San Francisco and cookbook author Mollie Katzen.&hellip;" />
<meta property="og:url" content="https://usapears.org/recipe/sauteed-bosc-pears/" />
<meta property="og:image" content="https://usapears.org/wp-content/uploads/2014/10/Sauteed-Bosc-Pears1.jpg" />
<meta property="og:type" content="article" />
<meta property="og:site_name" content="USA Pears" />
<meta property="article:tag" content="Bosc" />
<meta property="article:tag" content="Desserts" />
<meta property="article:section" content="Recipes" />
<meta property="article:published_time" content="2014-10-21T20:58:25+00:00" />
<meta property="article:modified_time" content="2020-07-24T06:27:30+00:00" />
<meta property="og:updated_time" content="2020-07-24T06:27:30+00:00" />

<meta property="og:title" content="Sauteed Bosc Pears" />
<meta property="og:description" content="This simple, tasty pear recipe was created by Chef Jamie Lauren of Absinthe Brasserie and Bar in San Francisco and cookbook author Mollie Katzen.&hellip;" />
<meta property="og:url" content="https://usapears.org/recipe/sauteed-bosc-pears/" />
<meta property="og:image" content="https://usapears.org/wp-content/uploads/2014/10/Sauteed-Bosc-Pears1.jpg" />
<meta property="og:type" content="article" />
<meta property="og:site_name" content="USA Pears" />
<meta property="article:tag" content="Bosc" />
<meta property="article:tag" content="Desserts" />
<meta property="article:section" content="Recipes" />
<meta property="article:published_time" content="2014-10-21T20:58:25+00:00" />
<meta property="article:modified_time" content="2020-07-24T06:27:30+00:00" />
<meta property="og:updated_time" content="2020-07-24T06:27:30+00:00" />


<!-- This site is optimized with the Yoast SEO plugin v15.3 - https://yoast.com/wordpress/plugins/seo/ -->
<meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
Expand Down Expand Up @@ -968,33 +968,33 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

</div> <!-- end container -->
</footer><!-- end #footer -->
<script>(function(){var s=document.createElement('script');e = !document.body ? document.querySelector('head'):document.body;s.src='https://acsbapp.com/apps/app/dist/js/app.js';s.defer=true;s.onload=function(){acsbJS.init({
statementLink : '',
feedbackLink : '',
footerHtml : '',
hideMobile : false,
hideTrigger : false,
language : 'en',
position : 'right',
leadColor : '#28a745',
triggerColor : '#28a745',
triggerRadius : '50%',
triggerPositionX : 'right',
triggerPositionY : 'bottom',
triggerIcon : 'people',
triggerSize : 'medium',
triggerOffsetX : 10,
triggerOffsetY : 90,
mobile : {
triggerSize : 'small',
triggerPositionX : 'right',
triggerPositionY : 'center',
triggerOffsetX : 0,
triggerOffsetY : 0,
triggerRadius : '50%'
}
});
};
<script>(function(){var s=document.createElement('script');e = !document.body ? document.querySelector('head'):document.body;s.src='https://acsbapp.com/apps/app/dist/js/app.js';s.defer=true;s.onload=function(){acsbJS.init({
statementLink : '',
feedbackLink : '',
footerHtml : '',
hideMobile : false,
hideTrigger : false,
language : 'en',
position : 'right',
leadColor : '#28a745',
triggerColor : '#28a745',
triggerRadius : '50%',
triggerPositionX : 'right',
triggerPositionY : 'bottom',
triggerIcon : 'people',
triggerSize : 'medium',
triggerOffsetX : 10,
triggerOffsetY : 90,
mobile : {
triggerSize : 'small',
triggerPositionX : 'right',
triggerPositionY : 'center',
triggerOffsetX : 0,
triggerOffsetY : 0,
triggerRadius : '50%'
}
});
};
e.appendChild(s);}());</script><script type='text/javascript' id='contact-form-7-js-extra'>
/* <![CDATA[ */
var wpcf7 = {"apiSettings":{"root":"https:\/\/usapears.org\/wp-json\/contact-form-7\/v1","namespace":"contact-form-7\/v1"}};
Expand Down
86 changes: 86 additions & 0 deletions tests/test_data/usapears.org/usapears_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"author": "George Barberis",
"canonical_url": "https://usapears.org/recipe/pulled-pork-and-pear-tacos-with-pear-pico-de-gallo/",
"site_name": "USA Pears",
"host": "usapears.org",
"language": "en-US",
"title": "Pulled Pork and Pear Tacos with Pear Pico de Gallo",
"ingredients": [
"3 1/2 pounds pork shoulder (pork butt)",
"1 tablespoon kosher salt",
"1 tablespoon chile powder",
"2 teaspoons ground cumin",
"1/2 teaspoon freshly ground pepper",
"1 tablespoon extra-virgin olive oil",
"2 large ripe USA Pears, peeled and chopped",
"1 small white onion, finely chopped",
"1/4 cup chopped fresh cilantro leaves and stems",
"4 canned chipotle chiles with a little extra sauce",
"2 cloves garlic, minced",
"Juice of 1 lime",
"1 1/2 cups finely diced USA Green Bartlett Pear",
"1 cup finely diced jicama",
"4 finely minced green onions",
"1/4 cup minced cilantro",
"2 minced jalapeños, or to taste",
"Juice of 1 lime",
"Kosher salt, to taste",
"Corn or flour tortillas, for serving",
"1 avocado, sliced",
"Sour cream, for serving"
],
"ingredient_groups": [
{
"ingredients": [
"3 1/2 pounds pork shoulder (pork butt)",
"1 tablespoon kosher salt",
"1 tablespoon chile powder",
"2 teaspoons ground cumin",
"1/2 teaspoon freshly ground pepper",
"1 tablespoon extra-virgin olive oil",
"2 large ripe USA Pears, peeled and chopped",
"1 small white onion, finely chopped",
"1/4 cup chopped fresh cilantro leaves and stems",
"4 canned chipotle chiles with a little extra sauce",
"2 cloves garlic, minced",
"Juice of 1 lime"
],
"purpose": "Pulled Pork"
},
{
"ingredients": [
"1 1/2 cups finely diced USA Green Bartlett Pear",
"1 cup finely diced jicama",
"4 finely minced green onions",
"1/4 cup minced cilantro",
"2 minced jalapeños, or to taste",
"Juice of 1 lime",
"Kosher salt, to taste",
"Corn or flour tortillas, for serving",
"1 avocado, sliced",
"Sour cream, for serving"
],
"purpose": "Pear Pico de Gallo"
}
],
"instructions_list": [
"To make the pulled pork: Cut the pork into 4 large chunks and season them with salt, chile powder, cumin, and pepper, coating all sides. Put the pork in a slow cooker and add the pears, onion, cilantro, chipotle chiles, and garlic, and squeeze the lime juice over everything. Cover and cook on until the meat easily shreds, 8 to 10 hours on low, or 4 to 6 hours on high. (This can also be cooked in an Instant Pot at high pressure for 75 minutes, following manufacturer’s instructions.) Shred the meat using two forks right in the slow cooker, discarding any fatty pieces. Keep warm.",
"To make the pico de gallo: Mix all ingredients in a small bowl up to 2 hours before serving.",
"Serve the pulled pork in warmed tortillas, topped with avocado, sour cream, and the pico de gallo, as desired.",
"(Leftover meat will keep in the refrigerator for up to 4 days, or can be frozen for up to 6 months.)",
"Photography: George Barberis (@georgebarberis)",
"Recipe and Styling: Andrea Slonecker (@andreaslonecker)"
],
"category": "Entrees",
"yields": "20 servings",
"description": "Time for a taco party! In this festive recipe, pears appear in two ways: braised with pork shoulder to create depth and sweetness for a juicy, shredded taco filling, and also mixed into a zesty pear and jicama pico de gallo for topping. There will be plenty of the flavorful slow-cooked meat to feed a crowd, and any leftovers can be frozen for quick taco making for future weeknight dinners. Serve with margaritas and chips and salsa to round out the menu.",
"total_time": 620,
"cuisine": "Mexican",
"nutrients": {
"servingSize": "1 Taco (178g)",
"calories": "410",
"carbohydrateContent": "27g",
"proteinContent": "23g"
},
"image": "https://usapears.org/wp-content/uploads/2018/05/UsaPears_0019-Copy.jpg"
}
Loading

0 comments on commit a648c1a

Please sign in to comment.