Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@
from .ricardocuisine import RicardoCuisine
from .ricetta import Ricetta
from .ricetteperbimby import RicettePerBimby
from .rickbayless import RickBayless
from .rosannapansino import RosannaPansino
from .rutgerbakt import RutgerBakt
from .saboresajinomoto import SaboresAjinomoto
Expand Down Expand Up @@ -1118,6 +1119,7 @@
RicardoCuisine.host(): RicardoCuisine,
Ricetta.host(): Ricetta,
RicettePerBimby.host(): RicettePerBimby,
RickBayless.host(): RickBayless,
RosannaPansino.host(): RosannaPansino,
RutgerBakt.host(): RutgerBakt,
SaboresAjinomoto.host(): SaboresAjinomoto,
Expand Down
44 changes: 44 additions & 0 deletions recipe_scrapers/rickbayless.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from ._abstract import AbstractScraper
from ._exceptions import StaticValueException
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from ._exceptions import StaticValueException
from ._exceptions import StaticValueException, FieldNotProvidedByWebsiteException
from ._utils import get_yields



class RickBayless(AbstractScraper):
@classmethod
def host(cls):
return "rickbayless.com"

def site_name(self):
raise StaticValueException(return_value="Rick Bayless")

def title(self):
header = self.soup.find("div", {"class": "page-header"})
return header.find("h1").get_text(strip=True)

def description(self):
desc = self.soup.find("div", {"class": "recipe-description"})
return desc.get_text(strip=True) if desc else None

def ingredients(self):
ingredients_div = self.soup.find("div", {"class": "recipe-ingredients"})
items = ingredients_div.find_all("li", {"itemprop": "ingredients"})
return [" ".join(li.get_text().split()) for li in items]

def instructions(self):
instructions_div = self.soup.find("div", {"class": "recipe-instructions"})
return "\n".join(
p.get_text().strip()
for p in instructions_div.find_all("p")
if p.get_text(strip=True)
)

def image(self):
og_image = self.soup.find("meta", {"property": "og:image"})
return og_image["content"] if og_image else None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def image(self):
og_image = self.soup.find("meta", {"property": "og:image"})
return og_image["content"] if og_image else None

The built in best_image functionality (see here) returns the same result so we can exclude the custom code here.

def yields(self):
servings = self.soup.find("div", {"class": "recipe-servings"})
if not servings:
return None
text = servings.get_text(strip=True)
result = text.replace("Servings:", "").strip()
return result or None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return result or None
return get_yields(result)
def total_time(self):
raise FieldNotProvidedByWebsiteException(return_value=None)
def author(self):
raise StaticValueException(return_value="Rick Bayless")

yields: There is a built in util that can be used to help standardize the output of the yields which helps maintain consistency in the output. There is a bug with this specific site that i'll be opening an issue for.
total_time: Since total time is a mandatory field we should raise FieldNotProvidedByWebsiteException to alert that this field isn't available from this site
author: Another mandatory field here but this time we can raise StaticValueException with the author's name as it seems they are the sole contributor to the site.

24 changes: 24 additions & 0 deletions tests/test_data/rickbayless.com/rickbayless.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"canonical_url": "https://www.rickbayless.com/recipe/mango-guacamole/",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"canonical_url": "https://www.rickbayless.com/recipe/mango-guacamole/",
"author": "Rick Bayless",
"canonical_url": "https://www.rickbayless.com/recipe/mango-guacamole/",

"site_name": "Rick Bayless",
"host": "rickbayless.com",
"language": "en-US",
"title": "Mango Guacamole",
"ingredients": [
"3 large avocados",
"1/2 small red onion, diced",
"1/2 to 1 fresh serrano chile, seeded and finely chopped",
"2 tablespoons chopped fresh cilantro, plus a few leaves for garnish",
"About 2 tablespoons fresh lime juice",
"1 medium ripe mango, peeled, flesh cut from the pit and diced",
"Salt"
],
"instructions_list": [
"Cut the avocados in half, running your knife around the pit from stem to blossom end and back up again. Twist the halves in opposite directions to free the pit, and pull the halves apart. Dislodge the pit, then scoop the avocado flesh into a large bowl. Coarsely mash the avocado with a large fork or potato masher. Rinse the onion under cold water, shake off the excess water, then add it to the avocado along with the serrano, cilantro and lime juice.",
"Mix in 2/3 of the diced mango. Taste and season with salt. If not using immediately, cover with plastic wrap pressed directly on the surface of the guacamole and refrigerate—preferably for no more than a few hours.",
"When you're ready to serve, scoop the guacamole into a serving bowl and garnish with the remaining diced mango and cilantro sprigs. Serve with tortilla chips, slices of cucumber or jicama."
],
"yields": "2 1/2 cups",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"yields": "2 1/2 cups",
"yields": "2 cups",

"description": "Recipe from Season 6, Mexico—One Plate at a Time",
"image": "https://www.rickbayless.com/wp-content/uploads/2013/12/Screen-Shot-2014-04-01-at-12.12.04-PM.png"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"image": "https://www.rickbayless.com/wp-content/uploads/2013/12/Screen-Shot-2014-04-01-at-12.12.04-PM.png"
"total_time": null,
"image": "https://www.rickbayless.com/wp-content/uploads/2013/12/Screen-Shot-2014-04-01-at-12.12.04-PM.png"

}
Loading