Skip to content

Commit

Permalink
Update hellofresh scraper to remove special handling of recipes that …
Browse files Browse the repository at this point in the history
…can be scaled to 1 portion. (#778)
  • Loading branch information
strangetom committed Jul 13, 2023
1 parent 0a875e8 commit 49fb944
Show file tree
Hide file tree
Showing 5 changed files with 625 additions and 634 deletions.
21 changes: 1 addition & 20 deletions recipe_scrapers/hellofresh.py
Expand Up @@ -17,10 +17,7 @@ def yields(self):
return self.schema.yields()

def ingredients(self):
if not self._serving_one_on_page():
return self.schema.ingredients()
else:
return [f"2 * {ingredient}" for ingredient in self.schema.ingredients()]
return self.schema.ingredients()

def instructions(self):
return self.schema.instructions()
Expand All @@ -36,19 +33,3 @@ def cuisine(self):

def category(self):
return self.schema.category()

def _serving_one_on_page(self):
# ad-hoc solution for https://github.com/hhursev/recipe-scrapers/issues/527
try:
return (
self.soup.find("div", {"data-test-id": "serving-amount-container"})
.find("div", {"class": "fela-_txm046"})
.select("div[class*=ds]")[0]
.get_text()
== "1"
)
except (AttributeError, IndexError):
# AttributeError if .find(..) method errored
# IndexError if the .select(..)[0] did not work as expected
# both cases to fall back to default behaviour
return True

0 comments on commit 49fb944

Please sign in to comment.