Skip to content

Commit

Permalink
Merge ca20dc6 into c6887ca
Browse files Browse the repository at this point in the history
  • Loading branch information
mlduff committed Jun 10, 2024
2 parents c6887ca + ca20dc6 commit 9291df7
Show file tree
Hide file tree
Showing 5 changed files with 1,346 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Scrapers available for:
- `https://aflavorjournal.com/ <https://aflavorjournal.com/>`_
- `https://ah.nl/ <https://ah.nl/>`_
- `https://akispetretzikis.com/ <https://akispetretzikis.com/>`_
- `https://aldi.com.au/ <https://aldi.com.au/>`_
- `https://alexandracooks.com/ <https://alexandracooks.com/>`_
- `https://alittlebityummy.com/ <https://alittlebityummy.com/>`_
- `https://allrecipes.com/ <https://allrecipes.com/>`_
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .aflavorjournal import AFlavorJournal
from .akispetretzikis import AkisPetretzikis
from .albertheijn import AlbertHeijn
from .aldi import Aldi
from .alexandracooks import AlexandraCooks
from .alittlebityummy import ALittleBitYummy
from .allrecipes import AllRecipes
Expand Down Expand Up @@ -364,6 +365,7 @@
AfghanKitchenRecipes.host(): AfghanKitchenRecipes,
AkisPetretzikis.host(): AkisPetretzikis,
AlbertHeijn.host(): AlbertHeijn,
Aldi.host(): Aldi,
AlexandraCooks.host(): AlexandraCooks,
AllRecipes.host(): AllRecipes,
AllTheHealthyThings.host(): AllTheHealthyThings,
Expand Down
68 changes: 68 additions & 0 deletions recipe_scrapers/aldi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# mypy: allow-untyped-defs
import re

from ._abstract import AbstractScraper
from ._utils import get_minutes, get_yields


class Aldi(AbstractScraper):
@classmethod
def host(cls):
return "aldi.com.au"

def site_name(self):
return "Aldi"

def author(self):
return self.soup.find("meta", {"name": "author"}).get("content")

def title(self):
return self.soup.find("h1").text

def category(self):
element = self.soup.select_one("a.tab-nav--link.dropdown--list--link.m-active")
if element:
title = element.text
recipe_position = title.find(" Recipe")
if recipe_position != -1:
return title[:recipe_position]

def prep_time(self):
return get_minutes(self._get_value(re.compile("prep", re.IGNORECASE)))

def cook_time(self):
return get_minutes(self._get_value(re.compile("cook", re.IGNORECASE)))

def total_time(self):
return (self.prep_time() or 0) + (self.cook_time() or 0)

def yields(self):
value = self._get_value(re.compile("(makes)|(serves)", re.IGNORECASE))
return get_yields(str(value))

def image(self):
figure = self.soup.find("figure", {"class": "csc-textpic-image csc-textpic-last"})
if figure:
image = figure.find("img")
if image:
return image.get("src")
return None

def ingredients(self):
h2 = self.soup.find("h2", string=re.compile("Ingredients"))
list_element = h2.find_next_sibling("ul")
ingredients = []
for li in list_element.find_all("li"):
ingredients.append(li.text.strip())
return ingredients

def instructions(self):
list_element = self.soup.find("ol")
return "\n".join(li.text.strip() for li in list_element.find_all("li"))

def _get_value(self, label):
label_element = self.soup.find("b", string=label)
if label_element:
parts = [sibling.strip() for sibling in label_element.find_next_siblings(string=True) if sibling.strip()]
return " ".join(parts)
return None
40 changes: 40 additions & 0 deletions tests/test_data/aldi.com.au/aldi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"author": "ALDI AU",
"canonical_url": "https://www.aldi.com.au/recipes/breakfast-recipes/overloaded-cheese-toastie-recipe/",
"host": "aldi.com.au",
"image": "https://www.aldi.com.au/fileadmin/_processed_/8/b/csm_1000340_WK23_PD_455x315__OVERLOADED-CHEESE-TOASTIE__1_RET_4506d46579.jpg",
"category": "Breakfast",
"ingredients": [
"1 tbsp Remano pesto",
"1 slice Westacre tasty cheese",
"3 slices tomato",
"2 slices sourdough bread",
"Handful of The Fresh Salad Co baby spinach"
],
"ingredient_groups": [
{
"purpose": null,
"ingredients": [
"1 tbsp Remano pesto",
"1 slice Westacre tasty cheese",
"3 slices tomato",
"2 slices sourdough bread",
"Handful of The Fresh Salad Co baby spinach"
]
}
],
"instructions": "Preheat a sandwich press.\nSpread pesto on one slice of bread and layer with cheese, tomato and spinach and close the sandwich with the remaining slice of bread.\nPlace the sandwich in the press and cook for 3-4 minutes or until the cheese melts and the sandwich is golden brown.\nAllow to cool slightly before serving.",
"instructions_list": [
"Preheat a sandwich press.",
"Spread pesto on one slice of bread and layer with cheese, tomato and spinach and close the sandwich with the remaining slice of bread.",
"Place the sandwich in the press and cook for 3-4 minutes or until the cheese melts and the sandwich is golden brown.",
"Allow to cool slightly before serving."
],
"language": "en-AU",
"site_name": "Aldi",
"title": "Overloaded Cheese Toastie Recipe",
"prep_time": 5,
"cook_time": 5,
"total_time": 10,
"yields": "1 serving"
}
Loading

0 comments on commit 9291df7

Please sign in to comment.