Skip to content

Commit

Permalink
Add Hassanchef scraper. Normalize instructions/ingredients strings wh…
Browse files Browse the repository at this point in the history
…en schema is used.
  • Loading branch information
hhursev committed Aug 22, 2020
1 parent 55e43d2 commit d07c428
Show file tree
Hide file tree
Showing 14 changed files with 1,704 additions and 54 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Scrapers available for:
- `https://gousto.co.uk/ <https://gousto.co.uk>`_
- `https://greatbritishchefs.com/ <https://greatbritishchefs.com>`_
- `https://halfbakedharvest.com/ <https://www.halfbakedharvest.com/>`_
- `https://www.hassanchef.com/ <https://www.hassanchef.com/>`_
- `https://heinzbrasil.com.br/ <https://heinzbrasil.com.br>`_
- `https://hellofresh.com/ <https://hellofresh.com>`_
- `https://hellofresh.co.uk/ <https://hellofresh.co.uk>`_
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .gousto import Gousto
from .greatbritishchefs import GreatBritishChefs
from .halfbakedharvest import HalfBakedHarvest
from .hassenchef import Hassanchef
from .heinzbrasil import HeinzBrasil
from .hellofresh import HelloFresh
from .hostthetoast import Hostthetoast
Expand Down Expand Up @@ -122,6 +123,7 @@
Gousto.host(): Gousto,
GreatBritishChefs.host(): GreatBritishChefs,
HalfBakedHarvest.host(): HalfBakedHarvest,
Hassanchef.host(): Hassanchef,
HeinzBrasil.host(): HeinzBrasil,
HelloFresh.host(): HelloFresh,
HelloFresh.host(domain="co.uk"): HelloFresh,
Expand Down
8 changes: 6 additions & 2 deletions recipe_scrapers/_schemaorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ def ingredients(self):
ingredients = (
self.data.get("recipeIngredient") or self.data.get("ingredients") or []
)
return [normalize_string(ingredient) for ingredient in ingredients]
return [
normalize_string(ingredient) for ingredient in ingredients if ingredient
]

def instructions(self):
instructions = self.data.get("recipeInstructions") or ""
if type(instructions) == list:
return "\n".join(
instruction.get("text") if type(instruction) is dict else instruction
normalize_string(instruction.get("text"))
if type(instruction) is dict
else normalize_string(instruction)
for instruction in instructions
)
return instructions
Expand Down
28 changes: 28 additions & 0 deletions recipe_scrapers/hassenchef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from ._abstract import AbstractScraper


class Hassanchef(AbstractScraper):
@classmethod
def host(cls):
return "hassanchef.com"

def title(self):
return self.schema.title()

def total_time(self):
return self.schema.total_time()

def yields(self):
return self.schema.yields()

def image(self):
return self.schema.image()

def ingredients(self):
return self.schema.ingredients()

def instructions(self):
return self.schema.instructions()

def ratings(self):
return self.schema.ratings()
10 changes: 1 addition & 9 deletions tests/test_bowlofdelicious.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ def test_ingredients(self):

def test_instructions(self):
return self.assertEqual(
"\n".join(
[
"Pat the ahi tuna steaks dry with a paper towel. Place on a plate or inside a plastic bag.",
"Mix the soy sauce (2 tablespoons), toasted sesame oil (1 tablespoon), honey (1 tablespoon) kosher salt (1/2 teaspoon- OMIT if marinating for more than a couple hours, see notes), pepper (1/4 teaspoon), and cayenne pepper (1/4 teaspoon) until honey is fully dissolved. Pour over the ahi tuna steaks and turn over to coat completely. Optional: allow to marinate for at least 10 minutes, or up to overnight in the refrigerator. Also optional: Reserve a spoonful or two of the marinade before coating the fish for drizzling on top after you&#039;ve cooked it.",
"Heat a medium skillet (preferably non-stick or a well-seasoned cast iron skillet) on medium-high to high until very hot ( or medium medium-high for nonstick). I recommend giving cast iron 3-5 minutes to get hot and nonstick about 1 minute, depending on how thick it is.",
"Add the canola oil (1 tablespoon) to the hot pan. Sear the tuna for 2 minutes on each side for medium rare (1.5 minutes on each side for rare; 3 on each side for medium). (Note: different burners get hotter depending on your stove. Use your best judgement whether you use medium, medium-high, or high heat, as the marinade may burn if too high heat is used)",
"Remove to a cutting board and allow to rest for at least 3 minutes. Slice into 1/2 inch slices and serve garnished with green onions, toasted sesame seeds, and a squeeze of fresh lime juice, if desired.",
]
),
"Pat the ahi tuna steaks dry with a paper towel. Place on a plate or inside a plastic bag.\nMix the soy sauce (2 tablespoons), toasted sesame oil (1 tablespoon), honey (1 tablespoon) kosher salt (1/2 teaspoon- OMIT if marinating for more than a couple hours, see notes), pepper (1/4 teaspoon), and cayenne pepper (1/4 teaspoon) until honey is fully dissolved. Pour over the ahi tuna steaks and turn over to coat completely. Optional: allow to marinate for at least 10 minutes, or up to overnight in the refrigerator. Also optional: Reserve a spoonful or two of the marinade before coating the fish for drizzling on top after you've cooked it.\nHeat a medium skillet (preferably non-stick or a well-seasoned cast iron skillet) on medium-high to high until very hot ( or medium medium-high for nonstick). I recommend giving cast iron 3-5 minutes to get hot and nonstick about 1 minute, depending on how thick it is.\nAdd the canola oil (1 tablespoon) to the hot pan. Sear the tuna for 2 minutes on each side for medium rare (1.5 minutes on each side for rare; 3 on each side for medium). (Note: different burners get hotter depending on your stove. Use your best judgement whether you use medium, medium-high, or high heat, as the marinade may burn if too high heat is used)\nRemove to a cutting board and allow to rest for at least 3 minutes. Slice into 1/2 inch slices and serve garnished with green onions, toasted sesame seeds, and a squeeze of fresh lime juice, if desired.",
self.harvester_class.instructions(),
)
2 changes: 1 addition & 1 deletion tests/test_cookpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def test_ingredients(self):

def test_instructions(self):
return self.assertEqual(
"鶏モモ肉 は一口大に、 玉ねぎ は薄切り(orみじん切り)にします♪\nフライパンに バター(大さじ2) を熱し、鶏肉 に 塩胡椒 をふり表面をこんがり焼きます♪\nお鍋に バター(大さじ3) にんにくチューブ 生姜チューブ 玉ねぎ を入れてあめ色になるまでじっくり炒めます♪\nカレー粉 を加えて弱火で3分くらい炒めます♪\n* と 鶏肉(油分も) を加えて沸騰したら火が通るまで(10分程)煮ます♪\n仕上げに 生クリーム を加えて混ぜ、温まったらすぐ火を止めます♪\n完成♡♡\n更に仕上げに生クリームをトッピングしました\n子供ごはんはこんな感じの盛り付けに♡♥",
"鶏モモ肉 は一口大に、 玉ねぎ は薄切り(orみじん切り)にします♪\nフライパンに バター(大さじ2) を熱し、鶏肉 に 塩胡椒 をふり表面をこんがり焼きます♪\nお鍋に バター(大さじ3) にんにくチューブ 生姜チューブ 玉ねぎ を入れてあめ色になるまでじっくり炒めます♪\nカレー粉 を加えて弱火で3分くらい炒めます♪\n* と 鶏肉(油分も) を加えて沸騰したら火が通るまで(10分程)煮ます♪\n仕上げに 生クリーム を加えて混ぜ、温まったらすぐ火を止めます♪ 完成♡♡ 更に仕上げに生クリームをトッピングしました\n子供ごはんはこんな感じの盛り付けに♡♥",
self.harvester_class.instructions(),
)
Loading

0 comments on commit d07c428

Please sign in to comment.