Skip to content

Commit

Permalink
feat: add omnivores cookbook (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
wengtad committed Oct 19, 2022
1 parent 89a0a67 commit cc913ac
Show file tree
Hide file tree
Showing 5 changed files with 1,353 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -229,6 +229,7 @@ Scrapers available for:
- `https://nutritionbynathalie.com/blog <https://nutritionbynathalie.com/blog>`_
- `https://cooking.nytimes.com/ <https://cooking.nytimes.com>`_
- `https://ohsheglows.com/ <https://ohsheglows.com>`_
- `https://omnivorescookbook.com <https://omnivorescookbook.com>`_
- `https://owen-han.com/ <https://owen-han.com>`_
- `https://101cookbooks.com/ <https://101cookbooks.com/>`_
- `https://www.paleorunningmomma.com/ <https://www.paleorunningmomma.com>`_
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Expand Up @@ -145,6 +145,7 @@
from .nutritionbynathalie import NutritionByNathalie
from .nytimes import NYTimes
from .ohsheglows import OhSheGlows
from .omnivorescookbook import OmnivoresCookbook
from .onehundredonecookbooks import OneHundredOneCookBooks
from .owenhan import OwenHan
from .paleorunningmomma import PaleoRunningMomma
Expand Down Expand Up @@ -371,6 +372,7 @@
NourishedByNutrition.host(): NourishedByNutrition,
NutritionByNathalie.host(): NutritionByNathalie,
OhSheGlows.host(): OhSheGlows,
OmnivoresCookbook.host(): OmnivoresCookbook,
OneHundredOneCookBooks.host(): OneHundredOneCookBooks,
OwenHan.host(): OwenHan,
PaleoRunningMomma.host(): PaleoRunningMomma,
Expand Down
46 changes: 46 additions & 0 deletions recipe_scrapers/omnivorescookbook.py
@@ -0,0 +1,46 @@
# mypy: allow-untyped-defs

from ._abstract import AbstractScraper
from ._utils import normalize_string


class OmnivoresCookbook(AbstractScraper):
@classmethod
def host(cls):
return "omnivorescookbook.com"

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

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

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

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):
ingredients = self.soup.find(
"ul", {"class": "wprm-recipe-ingredients"}
).find_all("li")
return [normalize_string(ingredient.get_text()) for ingredient in ingredients]

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

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

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

def description(self):
return self.soup.head.find("meta", {"property": "og:description"})["content"]
1,238 changes: 1,238 additions & 0 deletions tests/test_data/omnivorescookbook.testhtml

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions tests/test_omnivorescookbook.py
@@ -0,0 +1,66 @@
# mypy: allow-untyped-defs

from recipe_scrapers.omnivorescookbook import OmnivoresCookbook
from tests import ScraperTest


class TestOmnivoresCookbookScraper(ScraperTest):

scraper_class = OmnivoresCookbook

def test_host(self):
self.assertEqual("omnivorescookbook.com", self.harvester_class.host())

def test_author(self):
self.assertEqual("Maggie Zhu", self.harvester_class.author())

def test_title(self):
self.assertEqual(
"Stir Fried Bok Choy with Tofu Puffs", self.harvester_class.title()
)

def test_category(self):
self.assertEqual("Side", self.harvester_class.category())

def test_total_time(self):
self.assertEqual(15, self.harvester_class.total_time())

def test_yields(self):
self.assertEqual("2 servings", self.harvester_class.yields())

def test_image(self):
self.assertEqual(
"https://omnivorescookbook.com/wp-content/uploads/2022/02/211213_Stir-Fried-Bok-Choy-With-Tofu-Puffs_550.jpg",
self.harvester_class.image(),
)

def test_ingredients(self):
self.assertEqual(
[
"1 lb (450 g) bok choy , chopped to bite size pieces (see the cutting method in the post above)",
"1 heaping cup (60 grams) tofu puffs , halved",
"2 green onions , sliced",
"1 tablespoon peanut oil (or vegetable oil)",
"1 teaspoon sugar",
"2 tablespoons light soy sauce (or soy sauce)",
],
self.harvester_class.ingredients(),
)

def test_instructions(self):
self.assertEqual(
"Heat 1 tablespoon of oil in a medium-sized wok or large skillet over high heat until hot. Add scallion and stir a few times until fragrant.\nAdd bok choy. Stir and cook for 1 to 2 minutes, to coat evenly with oil.\nSprinkle it with sugar and swirl in light soy sauce. Immediately stir a few times to mix well. Add deep fried tofu, then stir again for about 20 seconds.\nCover the wok and lower to medium-low heat. Steam for 30 seconds. Uncover and stir to check the doneness. Cover and cook for another 10 to 20 seconds again, if necessary, until the bok choy is cooked through and slightly caramelized on the edges. Turn off the heat and transfer everything to a serving plate.\nServe hot as a side dish or over steamed rice as a light main dish.",
self.harvester_class.instructions(),
)

def test_ratings(self):
self.assertEqual(5.0, self.harvester_class.ratings())

def test_cuisine(self):
self.assertEqual("Chinese", self.harvester_class.cuisine())

def test_description(self):
self.assertEqual(
"A super quick and easy stir fried bok choy with tofu puffs that only uses five ingredients and takes 15 minutes to prep and cook.",
self.harvester_class.description(),
)

0 comments on commit cc913ac

Please sign in to comment.