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
+
+
100g Naked Tofoo, sliced
1 demi baguette
1/2 tsp soy sauce
@@ -518,200 +270,335 @@ var pysOptions = {"staticEvents":{"facebook":{"init_event":[{"delay":0,"type":"s
1/4 tsp Sriracha
Squeeze of lime
+
+
+
-
-
-
-
-
-
-
- Do this stuff
-
+
+
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.
Shred the Daikon, Carrot & Cucumber and lightly pickle in the rice vinegar for 10-20 minutes.
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.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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.
-
-
-
-
-
×
-
+
+
-
-
-
+