Skip to content

Commit

Permalink
Closetcooking scraper implementation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hhursev committed Oct 8, 2015
1 parent 9a913f2 commit c897f94
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ If you are programmer PRs with fixes are warmly welcomed and acknowledged with a
- [http://bbc.co.uk/](http://bbc.co.uk/food/recipes/)
- [http://bbcgoodfood.com/](http://bbcgoodfood.com/)
- [http://bonappetit.com/](http://bonappetit.com/)
- [http://closetcooking.com/](http://closetcooking.com/)
- [http://cookstr.com/](http://cookstr.com/)
- [http://epicurious.com/](http://epicurious.com/)
- [http://finedininglovers.com/](https://finedininglovers.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 @@ -4,6 +4,7 @@
from .bbcfood import BBCFood
from .bbcgoodfood import BBCGoodFood
from .bonappetit import BonAppetit
from .closetcooking import ClosetCooking
from .cookstr import Cookstr
from .epicurious import Epicurious
from .finedininglovers import FineDiningLovers
Expand All @@ -27,6 +28,7 @@
BBCFood.host(): BBCFood,
BBCGoodFood.host(): BBCGoodFood,
BonAppetit.host(): BonAppetit,
ClosetCooking.host(): ClosetCooking,
Cookstr.host(): Cookstr,
Epicurious.host(): Epicurious,
FineDiningLovers.host(): FineDiningLovers,
Expand Down
31 changes: 31 additions & 0 deletions recipe_scrapers/closetcooking.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 ClosetCooking(AbstractScraper):

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

def title(self):
return normalize_string(self.soup.find('h2', {'class': 'post-title'}).get_text())

def total_time(self):
return get_minutes(self.soup.find('meta', {'itemprop': 'totalTime'}))

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.findAll('li', {'itemprop': 'recipeInstructions'})

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

from recipe_scrapers.closetcooking import ClosetCooking


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

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

def test_title(self):
self.assertEqual(
self.harvester_class.title(),
'Bacon Wrapped Jalapeno Popper Stuffed Chicken'
)

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

def test_ingredients(self):
self.assertListEqual(
[
'4 (6 ounce) chicken breasts, pounded thin',
'salt and pepper to taste',
'4 jalapenos, diced',
'4 ounces cream cheese, room temperature',
'1 cup cheddar cheese, shredded',
'8 slices bacon'
],
self.harvester_class.ingredients()
)

def test_instructions(self):
return self.assertEqual(
'Lay the chicken flat, season both sides with salt and pepper, place 1/4 of the mixture of the jalapenos, cream cheese and cheddar on the chicken and roll them up.\nWrap each chicken breast up in 2 slices of bacon and place them in a baking dish on a wire rack.\nBake in a pre-heated 400F/200C oven until cooked, about 25-35 minutes.',
self.harvester_class.instructions()
)
1 change: 1 addition & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from recipe_scrapers.tests.test_bbcfood import *
from recipe_scrapers.tests.test_bbcgoodfood import *
from recipe_scrapers.tests.test_bonappetit import *
from recipe_scrapers.tests.test_closetcooking import *
from recipe_scrapers.tests.test_cookstr import *
from recipe_scrapers.tests.test_epicurious import *
from recipe_scrapers.tests.test_finedininglovers import *
Expand Down

0 comments on commit c897f94

Please sign in to comment.