Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add omnivores cookbook #647

Merged
merged 2 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
@@ -1,7 +1,7 @@
[flake8]
# FS002 comes from pugin "flake8-use-fstring"
# and would error on `str.format()` usage
ignore = E203, E266, E501, W503, FS002
ignore = E203, E266, E501, W503, FS002, FS003
max-line-length = 88
max-complexity = 18
select = B,C,E,F,W,T4,B9
Expand Down
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.schema.description()
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. The crisp bok choy is lightly caramelized and combined with tender tofu in a savory and slightly sweet sauce. It is surprisingly satisfying to eat as a side dish, and sometimes I serve it as a light main dish for lunch over steamed rice. {Vegan, Gluten-Free Adaptable}To make the dish gluten-free, use tamari to replace light soy sauce.",
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
self.harvester_class.description(),
)