Skip to content

Commit

Permalink
Ad-hoc solution for wrong ingredients amount in hellofresh when servi…
Browse files Browse the repository at this point in the history
…ng size 1 exists. Closes #527 (#643)
  • Loading branch information
hhursev committed Oct 16, 2022
1 parent f0d45d0 commit c074623
Show file tree
Hide file tree
Showing 4 changed files with 468 additions and 2 deletions.
21 changes: 20 additions & 1 deletion recipe_scrapers/hellofresh.py
Expand Up @@ -17,7 +17,10 @@ def yields(self):
return self.schema.yields()

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

def instructions(self):
return self.schema.instructions()
Expand All @@ -33,3 +36,19 @@ 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 c074623

Please sign in to comment.