diff --git a/recipe_scrapers/tofoo.py b/recipe_scrapers/tofoo.py index 76121ad28..2334ed482 100644 --- a/recipe_scrapers/tofoo.py +++ b/recipe_scrapers/tofoo.py @@ -1,8 +1,9 @@ import re from ._abstract import AbstractScraper +from ._exceptions import StaticValueException from ._grouping_utils import group_ingredients -from ._utils import normalize_string +from ._utils import get_minutes class Tofoo(AbstractScraper): @@ -11,52 +12,59 @@ def host(cls): return "tofoo.co.uk" def author(self): - return "The Tofoo co." + raise StaticValueException(return_value="The Tofoo co.") def title(self): - return self.soup.find( - "h1", {"class": "recipe-detail__title h3 blue"} - ).get_text() + return self.soup.find("div", {"class": "hero__content"}).find("h1").get_text() - def category(self): - category_text = self.soup.find( - "div", {"class": "recipe-detail__ins h6"} - ).get_text() - normalized_category = normalize_string(category_text) - return normalized_category + def _find_hero_stat(self, label): + hero_stats = self.soup.find("ul", {"class": "hero__stats"}) + if hero_stats: + for li in hero_stats.find_all("li"): + if re.search(rf"{label}:", li.get_text()): + return li.get_text() + return None def yields(self): - desc = self.soup.find("div", {"class": "recipe-detail__desc"}).get_text() - match = re.search(r"Serves (\d+)", desc) - if match: - return int(match.group(1)) + serves_text = self._find_hero_stat("Serves") + if serves_text: + match = re.search(r"Serves:\s*(\d+)", serves_text) + if match: + return int(match.group(1)) + return None - def total_time(self): - desc = self.soup.find("div", {"class": "recipe-detail__desc"}).get_text() - - prep_time_match = re.search(r"Prep (\d+) min", desc) - cooking_time_match = re.search(r"Cooking (\d+) min", desc) + def prep_time(self): + prep_text = self._find_hero_stat("Prep") + return get_minutes(prep_text) if prep_text else 0 - prep_time = int(prep_time_match.group(1)) if prep_time_match else 0 - cooking_time = int(cooking_time_match.group(1)) if cooking_time_match else 0 + def cook_time(self): + cook_text = self._find_hero_stat("Cooking") + return get_minutes(cook_text) if cook_text else 0 - return prep_time + cooking_time # Return the summed time in minutes + def total_time(self): + return self.prep_time() + self.cook_time() def ingredients(self): - ingredients_div = self.soup.find("div", {"class": "block-raw-material__body"}) - ingredients = [li.get_text() for li in ingredients_div.find_all("li")] - return ingredients + ingredients_div = self.soup.find( + "div", {"class": "recipe_details__ingredients"} + ) + return [li.get_text() for li in ingredients_div.find_all("li")] def ingredient_groups(self): return group_ingredients( self.ingredients(), self.soup, - ".block-raw-material h5", - ".block-raw-material li", + ".recipe_details__ingredient h5", + ".recipe_details__ingredient li", ) def instructions(self): - instructions_div = self.soup.find("div", {"class": "sect--do-this__title"}) - ol = instructions_div.find_next_sibling("ol") - instructions = [li.get_text() for li in ol.find_all("li")] - return "\n".join(instructions) + instructions_div = self.soup.find("div", {"class": "recipe_details__steps"}) + ol = instructions_div.find("div", {"class": "recipe_details__steps__ol"}).find( + "ol" + ) + return "\n".join([li.get_text() for li in ol.find_all("li")]) + + def keywords(self): + hero_cats = self.soup.find("ul", {"class": "hero__cats"}) + return [li.get_text() for li in hero_cats.find_all("li")] if hero_cats else [] diff --git a/tests/test_data/tofoo.co.uk/tofoo_1.json b/tests/test_data/tofoo.co.uk/tofoo_1.json index e433eec42..96d5828a4 100644 --- a/tests/test_data/tofoo.co.uk/tofoo_1.json +++ b/tests/test_data/tofoo.co.uk/tofoo_1.json @@ -3,7 +3,7 @@ "canonical_url": "https://tofoo.co.uk/recipes/banh-mi-2/", "site_name": "Tofoo", "host": "tofoo.co.uk", - "language": "en-US", + "language": "en-GB", "title": "Banh Mi", "ingredients": [ "100g Naked Tofoo, sliced", @@ -24,30 +24,6 @@ "1/4 tsp Sriracha", "Squeeze of lime" ], - "ingredient_groups": [ - { - "ingredients": [ - "100g Naked Tofoo, sliced", - "1 demi baguette", - "1/2 tsp soy sauce", - "1/2 lime, zested", - "1/2 tsp grated ginger", - "1/4 tsp garlic paste", - "10g daikon, shredded", - "10g carrot, shredded", - "10g cucumber, shredded", - "1 tbsp rice vinegar", - "oil", - "1g red chilli, sliced", - "10g radish, sliced", - "20g coriander (approx 10 sprigs)", - "Freshly ground black pepper.", - "1/4 tsp Sriracha", - "Squeeze of lime" - ], - "purpose": "Get this stuff" - } - ], "instructions_list": [ "Slice the Baguette in half lengthways. Mix together the soy sauce, lime zest, ginger, and garlic in a bowl.", "Marinade the Tofoo for 30 minutes.", @@ -55,8 +31,15 @@ "Heat a frying pan, add the oil, and lightly fry the Tofoo for a few minutes until it turns golden brown. Allow to cool.", "Place all the fillings into the baguette, in layers, and drizzle over the Sriracha. Season with pepper and finish with a squeeze of lime." ], - "category": "Vegan", "yields": 1, "total_time": 35, - "image": "https://tofoo.co.uk/wp-content/uploads/2020/09/Tofoo_Banh_Mi3134_v3_WebHeader.jpg" + "cook_time": 5, + "prep_time": 30, + "image": "https://tofoo.co.uk/wp-content/uploads/2020/09/Tofoo_Banh_Mi3134_v3_WebHeader.jpg", + "keywords": [ + "Naked", + "Dinner", + "Fakeaway", + "Lunch" + ] } diff --git a/tests/test_data/tofoo.co.uk/tofoo_1.testhtml b/tests/test_data/tofoo.co.uk/tofoo_1.testhtml index 36d5bbfa0..6d12e1598 100644 --- a/tests/test_data/tofoo.co.uk/tofoo_1.testhtml +++ b/tests/test_data/tofoo.co.uk/tofoo_1.testhtml @@ -1,505 +1,257 @@ + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Banh Mi - Tofoo - - - + + + + + + + + + + + + Banh Mi | Tofoo - + - + - + + - + + + + - - - - - - - + + + + + + + + + - - - - - + + + - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- -
-
-

Banh Mi

-
Serves 1 • Prep 30 min • Cooking 5 min
-
Vegan
- - - -
-
-
-
-
- -
-
-
-

 

-
Get this stuff
-
    + + +
    +
    +
    +
      +
    • Naked
    • +
    • Dinner
    • +
    • Fakeaway
    • +
    • Lunch
    • +
    + +

    Banh Mi

    + +
      +
    • Serves: 1 people
    • + +
    • Prep: 30 mins
    • + +
    • Cooking: 5 mins
    • +
    + + Get started +
    +
    +
    + + +
    +
    + +
    +
    + +
    + +
    +
    +
    +

    Ingredients

    +
    +
    1. 100g Naked Tofoo, sliced
    2. 1 demi baguette
    3. 1/2 tsp soy sauce
    4. @@ -518,200 +270,335 @@ var pysOptions = {"staticEvents":{"facebook":{"init_event":[{"delay":0,"type":"s
    5. 1/4 tsp Sriracha
    6. Squeeze of lime
    +
    +
    +
    +

    Get started

    -
    -
    -
    - -
    -
-
-
-
-
Do this stuff
-
    +
    +
    1. Slice the Baguette in half lengthways. Mix together the soy sauce, lime zest, ginger, and garlic in a bowl.
    2. Marinade the Tofoo for 30 minutes.
    3. Shred the Daikon, Carrot & Cucumber and lightly pickle in the rice vinegar for 10-20 minutes.
    4. Heat a frying pan, add the oil, and lightly fry the Tofoo for a few minutes until it turns golden brown. Allow to cool.
    5. Place all the fillings into the baguette, in layers, and drizzle over the Sriracha. Season with pepper and finish with a squeeze of lime.
    - -
-
- -
-
-
-
People also viewed
-
-
-
- +
- -
-
- View all recipes -
-
- -
- - - - - - - - + + + - - - - + + + + - - - - - - - - - - - - - - -
-
-
We use cookies to ensure that we give you the best experience on our website.
If you continue to use this site we will assume that you are happy with it.
- -
OK
-
X
-
-
-
We use cookies to ensure that we give you the best experience on our website.
If you continue to use this site we will assume that you are happy with it. - -
- -
- -
- OK -
- × -
+ + -
- - + \ No newline at end of file diff --git a/tests/test_data/tofoo.co.uk/tofoo_2.json b/tests/test_data/tofoo.co.uk/tofoo_2.json index e191b6b32..0c09f306e 100644 --- a/tests/test_data/tofoo.co.uk/tofoo_2.json +++ b/tests/test_data/tofoo.co.uk/tofoo_2.json @@ -3,7 +3,7 @@ "canonical_url": "https://tofoo.co.uk/recipes/sticky-sriracha-tofoo/", "site_name": "Tofoo", "host": "tofoo.co.uk", - "language": "en-US", + "language": "en-GB", "title": "Sticky Sriracha Tofoo", "ingredients": [ "1 pack of Naked Tofoo, cut into cubes", @@ -52,8 +52,17 @@ "Whisk all sauce ingredients in a small bowl and add to your Tofoo. Stir and cook for a few mins until all your Tofoo is evenly covered in sticky sauce.", "Meanwhile, cook your microwave rice as per the pack instructions and add into bowls before topping with your sticky Sriracha Tofoo. Scatter with spring onion and sesame seeds for the ultimate fakeaway, ready in only 20 mins!" ], - "category": "Vegans", "yields": 2, "total_time": 20, - "image": "https://tofoo.co.uk/wp-content/uploads/2023/07/StickySriracha-scaled.jpg" + "cook_time": 15, + "prep_time": 5, + "image": "https://tofoo.co.uk/wp-content/uploads/2023/07/StickySriracha-scaled-1.jpg", + "keywords": [ + "Naked", + "Beginners", + "Dinner", + "Fakeaway", + "Speedy", + "Stir-fry" + ] } diff --git a/tests/test_data/tofoo.co.uk/tofoo_2.testhtml b/tests/test_data/tofoo.co.uk/tofoo_2.testhtml index f5bafc42e..362e13080 100644 --- a/tests/test_data/tofoo.co.uk/tofoo_2.testhtml +++ b/tests/test_data/tofoo.co.uk/tofoo_2.testhtml @@ -1,502 +1,259 @@ + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sticky Sriracha Tofoo - Tofoo - - - + + + + + + + + + + + + Sticky Sriracha Tofoo | Tofoo - + - + - + + + - + + + + - - - - - - - + + + + + + + + + - - - - - + + + - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- -
-
-

Sticky Sriracha Tofoo

-
Serves 2 • Prep 5 min • Cooking 15 min
-
Vegans
+ +
+
- - -
-
- + + + + +
+
+
+
    +
  • Naked
  • +
  • Beginners
  • +
  • Dinner
  • +
  • Fakeaway
  • +
  • Speedy
  • +
  • Stir-fry
  • +
+ +

Sticky Sriracha Tofoo

+ +
    +
  • Serves: 2 people
  • + +
  • Prep: 5 mins
  • + +
  • Cooking: 15 mins
  • +
+ + Get started +
+
+
-
-
-
-
For the Tofoo
+ +
+
+ +
+
+ +
+ +
+
+
+

Ingredients

+
+
For the Tofoo
  • 1 pack of Naked Tofoo, cut into cubes
  • 2 tbsp cornflour
  • @@ -516,199 +273,334 @@ var pysOptions = {"staticEvents":{"facebook":{"init_event":[{"delay":0,"type":"s
  • Sesame seeds
  • Sliced spring onion
+
+
+
+

Get started

-
-
-
- -
-
-
-
-
-
Do this stuff
-
    +
    +
    1. In a bowl, mix the cornflour with a pinch of pepper and toss your Tofoo cubes through until evenly covered.
    2. Heat your veg oil in a large frying pan over a medium heat. Once hot, add your Tofoo cubes and cook for 5 mins, turning them over until golden on all sides.
    3. Whisk all sauce ingredients in a small bowl and add to your Tofoo. Stir and cook for a few mins until all your Tofoo is evenly covered in sticky sauce.
    4. Meanwhile, cook your microwave rice as per the pack instructions and add into bowls before topping with your sticky Sriracha Tofoo. Scatter with spring onion and sesame seeds for the ultimate fakeaway, ready in only 20 mins!
    - -
-
- -
-
-
-
People also viewed
-
-
-
- +
- -
-
- View all recipes -
-
- -
- - - - - - - - + + + - - - - - - - - - - - + + + + - - - - - - - -
-
-
We use cookies to ensure that we give you the best experience on our website.
If you continue to use this site we will assume that you are happy with it.
- -
OK
-
X
-
-
-
We use cookies to ensure that we give you the best experience on our website.
If you continue to use this site we will assume that you are happy with it. - -
- -
- -
- OK -
- × -
+ + -
- - + \ No newline at end of file