Skip to content

Commit

Permalink
Add epicurious scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
hhursev committed Oct 8, 2015
1 parent 8710d06 commit 9a913f2
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ If you are programmer PRs with fixes are warmly welcomed and acknowledged with a
- [http://bbcgoodfood.com/](http://bbcgoodfood.com/)
- [http://bonappetit.com/](http://bonappetit.com/)
- [http://cookstr.com/](http://cookstr.com/)
- [http://epicurious.com/](http://epicurious.com/)
- [http://finedininglovers.com/](https://finedininglovers.com/)
- [http://foodrepublic.com/](http://foodrepublic.com)
- [http://jamieoliver.com/](http://www.jamieoliver.com/)
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .bbcgoodfood import BBCGoodFood
from .bonappetit import BonAppetit
from .cookstr import Cookstr
from .epicurious import Epicurious
from .finedininglovers import FineDiningLovers
from .foodrepublic import FoodRepublic
from .hundredandonecookbooks import HundredAndOneCookbooks
Expand All @@ -27,6 +28,7 @@
BBCGoodFood.host(): BBCGoodFood,
BonAppetit.host(): BonAppetit,
Cookstr.host(): Cookstr,
Epicurious.host(): Epicurious,
FineDiningLovers.host(): FineDiningLovers,
FoodRepublic.host(): FoodRepublic,
HundredAndOneCookbooks.host(): HundredAndOneCookbooks,
Expand Down
31 changes: 31 additions & 0 deletions recipe_scrapers/epicurious.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ._abstract import AbstractScraper
from ._utils import get_minutes, normalize_string


class Epicurious(AbstractScraper):

@classmethod
def host(self):
return 'epicurious.com'

def title(self):
return self.soup.find('h1', {'itemprop': 'name'}).get_text()

def total_time(self):
return get_minutes(self.soup.findAll('p', {'class': 'summary_data'})[-1])

def ingredients(self):
ingredients_html = self.soup.findAll('li', {'itemprop': "ingredients"})

return [
normalize_string(ingredient.get_text())
for ingredient in ingredients_html
]

def instructions(self):
instructions_html = self.soup.find('div', {'id': 'preparation'}).find_all('p')

return '\n'.join([
normalize_string(instruction.get_text())
for instruction in instructions_html
])
62 changes: 62 additions & 0 deletions recipe_scrapers/tests/test_epicurious.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import unittest

from recipe_scrapers.epicurious import Epicurious


class TestEpicurious(unittest.TestCase):
def setUp(self):
# tests are run from tests.py
with open(os.path.join(
os.getcwd(),
'recipe_scrapers',
'tests',
'test_data',
'epicurious.html'
)) as file_opened:
self.harvester_class = Epicurious(file_opened, test=True)

def test_host(self):
self.assertEqual(
'epicurious.com',
self.harvester_class.host()
)

def test_title(self):
self.assertEqual(
self.harvester_class.title(),
'Poached Eggs in Tomato Sauce with Chickpeas and Feta'
)

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

def test_ingredients(self):
self.assertListEqual(
[
'1/4 cup olive oil',
'1 medium onion, finely chopped',
'4 garlic cloves, coarsely chopped',
'2 jalapeños, seeded, finely chopped',
'1 15-ounce can chickpeas, drained',
'2 teaspoons Hungarian sweet paprika',
'1 teaspoon ground cumin',
'1 28-ounce can whole peeled tomatoes, crushed by hand, juices reserved',
'Kosher salt and freshly ground black pepper',
'1 cup coarsely crumbled feta',
'8 large eggs',
'1 tablespoon chopped flat-leaf parsley',
'1 tablespoon chopped fresh cilantro',
'Warm pita bread'
],
self.harvester_class.ingredients()
)

def test_instructions(self):
return self.assertEqual(
'Preheat oven to 425°F. Heat oil in a large ovenproof skillet over medium-high heat. Add onion, garlic, and jalapeños; cook, stirring occasionally, until onion is soft, about 8 minutes. Add chickpeas, paprika, and cumin and cook for 2 minutes longer.\nAdd crushed tomatoes and their juices. Bring to a boil, reduce heat to medium-low, and simmer, stirring occasionally, until sauce thickens slightly, about 15 minutes. Season to taste with salt and pepper. Sprinkle feta evenly over sauce. Crack eggs one at a time and place over sauce, spacing evenly apart. Transfer skillet to oven and bake until whites are just set but yolks are still runny, 5-8 minutes. Garnish with parsley and cilantro. Serve with pita for dipping.\nPer serving: 358 calories, 22 g fat, 22 g carbohydrates\nNutritional analysis provided by Bon Appétit',
self.harvester_class.instructions()
)
1 change: 1 addition & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from recipe_scrapers.tests.test_bbcgoodfood import *
from recipe_scrapers.tests.test_bonappetit import *
from recipe_scrapers.tests.test_cookstr import *
from recipe_scrapers.tests.test_epicurious import *
from recipe_scrapers.tests.test_finedininglovers import *
from recipe_scrapers.tests.test_foodrepublic import *
from recipe_scrapers.tests.test_hundredandonecookbooks import *
Expand Down

0 comments on commit 9a913f2

Please sign in to comment.