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

Ingredient grouping support for Simplycookit #1360

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions recipe_scrapers/simplycookit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ._abstract import AbstractScraper
from ._exceptions import StaticValueException
from ._grouping_utils import IngredientGroup
from ._utils import normalize_string


Expand All @@ -14,6 +15,8 @@ def site_name(self):
def ingredients(self):
ingredients = []
for li in self.soup.find("ul", {"class": "recipe_ingredients"}).findAll("li"):
if li.find("h3"):
continue
ingredients.append(normalize_string(li.get_text()))

return ingredients
Expand All @@ -25,3 +28,34 @@ def instructions(self):
instructions.append(normalize_string(li.get_text()))

return "\n".join(instructions)

def ingredient_groups(self):
ingredient_groups = []

current_group = None
for li in self.soup.find("ul", {"class": "recipe_ingredients"}).findAll("li"):
h3 = li.find("h3")
if h3:
if current_group:
ingredient_groups.append(current_group)
current_group = IngredientGroup(
ingredients=[], purpose=normalize_string(h3.get_text())
)
else:
text = normalize_string(li.get_text())
if text:
if current_group:
current_group.ingredients.append(text)
else:
if not ingredient_groups:
ingredient_groups.append(IngredientGroup(ingredients=[]))
ingredient_groups[0].ingredients.append(text)

if current_group:
ingredient_groups.append(current_group)

return (
ingredient_groups
if ingredient_groups
else [IngredientGroup(ingredients=self.ingredients())]
)
34 changes: 0 additions & 34 deletions tests/test_data/simply-cookit.com/simplycookit.testhtml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "simply-cookit.com",
"canonical_url": "https://",
"canonical_url": "https://www.simply-cookit.com/de/rezepte/gnocchi-zuckerschoten-parmesansauce",
"site_name": "Simply Cookit",
"host": "simply-cookit.com",
"language": "de",
Expand Down
35 changes: 35 additions & 0 deletions tests/test_data/simply-cookit.com/simplycookit_1.testhtml

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions tests/test_data/simply-cookit.com/simplycookit_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"author": "simply-cookit.com",
"canonical_url": "https://www.simply-cookit.com/de/rezepte/pumpkin-pie",
"site_name": "Simply Cookit",
"host": "simply-cookit.com",
"language": "de",
"title": "Pumpkin Pie",
"ingredients": [
"200 g Weizenmehl 405",
"120 g Butter, kalt",
"60 g Zucker",
"40 ml Wasser, eiskalt",
"1 Prise Salz",
"1 Prise gemahlener Zimt",
"750 g Hokkaidokürbis",
"100 ml Wasser",
"200 g Doppelrahm-Frischkäse",
"120 g brauner Zucker",
"3 Eier",
"1 TL gemahlener Zimt",
"0,5 TL Ingwerpulver",
"1 Prise Muskatnusspulver",
"1 Msp. Pimentpulver",
"1 Prise Salz",
"Butter, zum Fetten",
"Weizenmehl 405, zum Bearbeiten"
],
"ingredient_groups": [
{
"ingredients": [
"200 g Weizenmehl 405",
"120 g Butter, kalt",
"60 g Zucker",
"40 ml Wasser, eiskalt",
"1 Prise Salz",
"1 Prise gemahlener Zimt"
],
"purpose": "Für den Teig"
},
{
"ingredients": [
"750 g Hokkaidokürbis",
"100 ml Wasser",
"200 g Doppelrahm-Frischkäse",
"120 g brauner Zucker",
"3 Eier",
"1 TL gemahlener Zimt",
"0,5 TL Ingwerpulver",
"1 Prise Muskatnusspulver",
"1 Msp. Pimentpulver",
"1 Prise Salz"
],
"purpose": "Für die Füllung"
},
{
"ingredients": [
"Butter, zum Fetten",
"Weizenmehl 405, zum Bearbeiten"
],
"purpose": "Außerdem"
}
],
"category": "Desserts & Backen",
"yields": "10 servings",
"description": "Der traditionelle Kürbiskuchen aus den USA zeichnet sich durch sein strahlendes Orange und die Vielfalt an Gewürzen aus. Die perfekte Verbindung aus cremiger Kürbisfüllung und knusprigem Mürbeteig. Nach 1 Stunde Abkühlzeit kannst du dich selber von dem unglaublichen Geschmack überzeugen. Für dieses Rezept benötigst du das Crushmesser.",
"total_time": 190,
"cook_time": 190,
"nutrients": {
"calories": "344 kcal",
"fatContent": "18 g",
"carbohydrateContent": "39 g",
"proteinContent": "7 g"
},
"image": "https://www.simply-cookit.com/sites/default/files/styles/square/public/assets/image/2024/10/pumpkin-pie_landscape.jpg?h=4727d466&itok=NZhYUH7F",
"keywords": [
"Desserts & Backen"
]
}
Loading
Loading