Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sally's Baking Addiction - take the last image in the list rather than the first #1034

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion recipe_scrapers/sallysbakingaddiction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# mypy: disallow_untyped_defs=False
from ._abstract import AbstractScraper
from ._exceptions import SchemaOrgException


class SallysBakingAddiction(AbstractScraper):
Expand Down Expand Up @@ -29,7 +30,21 @@ def yields(self):
return self.schema.yields()

def image(self):
return self.schema.image()
image = self.data.get("image")

if image is None:
raise SchemaOrgException("Image not found in SchemaOrg")

if isinstance(image, list):
image = image[-1]

if isinstance(image, dict):
image = image.get("url")

if "http://" not in image and "https://" not in image:
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to keep the comment that appeared below this line in the SchemaOrg original. Note that that's likely to be updated soon though, by pull request #1032.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, not sure why I removed that, think I caught myself in two minds between the initial version and more defensive version. If we go with this approach will add it back, better in your opinion to use the current one for consistency now and update after that PR gets merged, or just use the new version now?

image = ""

return image

def ingredients(self):
return self.schema.ingredients()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "Make a flavorful pull apart bread using this delicious rosemary-infused yeasted dough. You can use your favorite cheese in the filling. I love and usually use shredded parmesan.",
"cook_time": 50,
"host": "sallysbakingaddiction.com",
"image": "https://sallysbakingaddiction.com/wp-content/uploads/2020/12/garlic-rosemary-pull-apart-bread-225x225.jpg",
"image": "https://sallysbakingaddiction.com/wp-content/uploads/2020/12/garlic-rosemary-pull-apart-bread.jpg",
"ingredient_groups": [
{
"ingredients": [
Expand Down
Loading