Skip to content

Commit

Permalink
Adds support for okokorecepten (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
jknndy authored Jan 14, 2025
1 parent be58721 commit 7599ff3
Show file tree
Hide file tree
Showing 6 changed files with 1,397 additions and 0 deletions.
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
from .nutritionfacts import NutritionFacts
from .nytimes import NYTimes
from .ohsheglows import OhSheGlows
from .okokorecepten import OkokoRecepten
from .omnivorescookbook import OmnivoresCookbook
from .onceuponachef import OnceUponAChef
from .onehundredonecookbooks import OneHundredOneCookBooks
Expand Down Expand Up @@ -603,6 +604,7 @@
NoraCooks.host(): NoraCooks,
NotEnoughCinnamon.host(): NotEnoughCinnamon,
NutritionFacts.host(): NutritionFacts,
OkokoRecepten.host(): OkokoRecepten,
OneSweetAppetite.host(): OneSweetAppetite,
OttolenghiBooks.host(): OttolenghiBooks,
PeelWithZeal.host(): PeelWithZeal,
Expand Down
64 changes: 64 additions & 0 deletions recipe_scrapers/okokorecepten.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from ._abstract import AbstractScraper
from ._grouping_utils import IngredientGroup


class OkokoRecepten(AbstractScraper):
@classmethod
def host(cls):
return "okokorecepten.nl"

def instructions(self):
instructions = []

voorbereiden_section = self.soup.find(
"h2", string=lambda text: "Voorbereiden" in text
)
if voorbereiden_section:
for sibling in voorbereiden_section.find_next_siblings():
if sibling.name == "h2":
break
if sibling.name == "p":
instructions.append(sibling.get_text(strip=True))

bereiden_section = self.soup.find("h2", string=lambda text: "Bereiden" in text)
if bereiden_section:
for sibling in bereiden_section.find_next_siblings():
if sibling.name == "h2":
break
if sibling.name == "p":
instructions.append(sibling.get_text(strip=True))

return "\n".join(instructions)

def ingredient_groups(self):
ingredient_groups = []
ingredients_section = self.soup.find(
"h2", string=lambda text: "Ingrediënten" in text
)
if not ingredients_section:
return None

current_group = {"purpose": None, "ingredients": []}

for sibling in ingredients_section.find_next_siblings():
if sibling.name == "h2":
break
if sibling.name == "ul":
for li in sibling.find_all("li"):
if "tussenkop" in li.get("class", []):
if current_group["ingredients"]:
ingredient_groups.append(current_group)
current_group = {
"purpose": li.get_text(strip=True),
"ingredients": [],
}
else:
current_group["ingredients"].append(li.get_text(strip=True))

if current_group["ingredients"]:
ingredient_groups.append(current_group)

return [
IngredientGroup(ingredients=group["ingredients"], purpose=group["purpose"])
for group in ingredient_groups
]
48 changes: 48 additions & 0 deletions tests/test_data/okokorecepten.nl/okokorecepten_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"author": "okoko recepten",
"canonical_url": "okokorecepten.nl",
"site_name": "okoko recepten",
"host": "okokorecepten.nl",
"language": "nl",
"title": "Zuurkoolsoep",
"ingredients": [
"2 eetlepels olie",
"1 grote ui, gesnipperd",
"200 g zuurkool, uitgelekt en fijngesneden",
"½ blikje tomaatstukjes",
"2 theelepels tijm",
"2 kippenbouillontabletten",
"2 plakjes kipfilet (vleeswaar), in dunne reepjes",
"2 takjes basilicum, in fijne reepjes"
],
"category": "Voorgerecht",
"yields": "4 servings",
"description": "Zuurkoolsoep. Kijk voor de bereidingswijze op okokorecepten.nl.",
"total_time": 30,
"cook_time": 30,
"cuisine": "Hollands",
"ratings": 7.9,
"ratings_count": 18,
"nutrients": {
"calories": "75 kcal",
"fatContent": "5 g vet",
"carbohydrateContent": "4 g koolhydraten",
"proteinContent": "4 g eiwit"
},
"image": "https://www.okokorecepten.nl/i/recepten/redactie/2009-2/zuurkoolsoep-500.jpg",
"keywords": [
"recept",
"zuurkoolsoep",
"hollands",
"voorgerecht",
"gevogelte",
"olie",
"ui",
"zuurkool",
"tomaatstukjes",
"tijm",
"kippenbouillontablet",
"kipfilet",
"basilicum"
]
}
Loading

0 comments on commit 7599ff3

Please sign in to comment.