Skip to content

Commit

Permalink
reishunger.de: bugfixes and add support for multi-method recipes (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Oct 12, 2022
1 parent f5c5ec1 commit 5c033fb
Show file tree
Hide file tree
Showing 6 changed files with 6,758 additions and 3,389 deletions.
49 changes: 40 additions & 9 deletions recipe_scrapers/reishunger.py
@@ -1,4 +1,5 @@
# mypy: disallow_untyped_defs=False

from ._abstract import AbstractScraper
from ._utils import normalize_string

Expand Down Expand Up @@ -27,17 +28,47 @@ def ingredients(self):
return self.schema.ingredients()

def instructions(self):
result = self.soup.find("section", {"class": "recipe-preparation"})
if result:
result = "\n".join(
normalize_string(i.get_text()) for i in result.findAll("p")
)
return result
# find the "instructions" heading (Zubereitung in German)
for heading in self.soup.findAll("h3"):
if "Zubereitung" in heading.get_text():
break

results = []

# locate the first recipe instruction
step1 = heading.parent.parent.find("div", {"class": "leading-normal"})

# iterate through each step in the recipe
for step in step1.next_siblings:

# check whether the instruction has a list of preparations
# fixme: this can throw an exception if 'step' is not a bs4 Tag
try:
preparations = step.find("div", {"preparation": True})
except Exception:
preparations = None

# if it does, add every preparation step as an instruction entry
if preparations:
for preparation in preparations.findAll("div", {"id": True}):
instruction = normalize_string(preparation.text)
results.append(instruction)

# otherwise, add only one instruction entry
else:
if step.find("p"):
instruction = normalize_string(step.text)
results.append(instruction)

# continue on to the next instruction
step = step.next_sibling

# filter out empty lines
results = [instruction for instruction in results if instruction]
return "\n".join(results)

def ratings(self):
block = self.soup.find("div", {"id": "recipe-header"}).find(
"div", {"class": "nrating"}
)
block = self.soup.find("div", {"class": "nrating"})
if block:
cnt = len(block.findAll("span", {"class": "fa-star"}))
return cnt
Expand Down

0 comments on commit 5c033fb

Please sign in to comment.