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

Ad-hoc solution for wrong ingredients amount in hellofresh when serving size 1 exists. Closes #527 #643

Merged
merged 1 commit into from Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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