Skip to content

Commit

Permalink
Added support for przepisy.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
pzurakowski authored and hhursev committed Apr 6, 2020
1 parent dbb63da commit ffee963
Show file tree
Hide file tree
Showing 6 changed files with 1,215 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Scrapers available for:
- `http://mybakingaddiction.com/ <http://mybakingaddiction.com>`_
- `https://panelinha.com.br/ <https://panelinha.com.br>`_
- `http://paninihappy.com/ <http://paninihappy.com>`_
- `http://przepisy.pl/ <http://przepisy.pl>`_
- `http://realsimple.com/ <http://www.realsimple.com>`_
- `https://www.seriouseats.com/ <https://www.seriouseats.com>`_
- `http://simplyrecipes.com/ <http://www.simplyrecipes.co>`_
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 .nihhealthyeating import NIHHealthyEating
from .panelinha import Panelinha
from .paninihappy import PaniniHappy
from .przepisy import Przepisy
from .realsimple import RealSimple
from .seriouseats import SeriousEats
from .simplyrecipes import SimplyRecipes
Expand Down Expand Up @@ -89,6 +90,7 @@
NIHHealthyEating.host(): NIHHealthyEating,
Panelinha.host(): Panelinha,
PaniniHappy.host(): PaniniHappy,
Przepisy.host(): Przepisy,
RealSimple.host(): RealSimple,
SeriousEats.host(): SeriousEats,
SimplyRecipes.host(): SimplyRecipes,
Expand Down
50 changes: 50 additions & 0 deletions recipe_scrapers/przepisy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from ._abstract import AbstractScraper
from ._utils import get_minutes, normalize_string, get_yields


class Przepisy(AbstractScraper):

@classmethod
def host(self):
return 'przepisy.pl'

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

def total_time(self):
return get_minutes(self.soup.find(
'div',
{'class': 'time-count'})
)

def yields(self):
return get_yields(self.soup.find(
'div',
{'class': 'person-count'})
)

def ingredients(self):
ingredients = self.soup.findAll(
'span',
{'class': 'text-bg-white'}
)

return [
normalize_string(i.get_text()) + ' ' +
normalize_string(j.get_text())
for i, j in zip(ingredients[0::2], ingredients[1::2])
]

def instructions(self):
instructions = self.soup.findAll(
'p',
{'class': 'step-info-description'}
)

return '\n'.join([
normalize_string(instruction.get_text())
for instruction in instructions
])
1,099 changes: 1,099 additions & 0 deletions recipe_scrapers/tests/test_data/przepisy.testhtml

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions recipe_scrapers/tests/test_przepisy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import unittest

from recipe_scrapers.przepisy import Przepisy

# test recipe's URL
# https://www.przepisy.pl/przepis/placki-ziemniaczane


class TestPrzepisyScraper(unittest.TestCase):
def setUp(self):
# tests are run from tests.py
with open(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'test_data',
'przepisy.testhtml'
)) as file_opened:
self.harvester_class = Przepisy(file_opened, test=True)

def test_host(self):
self.assertEqual(
'przepisy.pl',
self.harvester_class.host()
)

def test_title(self):
self.assertEqual(
'Placki ziemniaczane',
self.harvester_class.title()
)

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

def test_yields(self):
self.assertEqual(
'8 serving(s)',
self.harvester_class.yields()
)

def test_ingredients(self):
self.assertEqual(
[
'ziemniaki 1 kilogram',
'cebula 1 sztuka',
'jajka 2 sztuki',
'Przyprawa w Mini kostkach Czosnek Knorr 1 sztuka',
'Gałka muszkatołowa z Indonezji Knorr 1 szczypta',
'sól 1 szczypta',
'mąka 3 łyżki'
],
self.harvester_class.ingredients()
)

def test_instructions(self):
self.assertEqual(
'Obierz ziemniaki, zetrzyj na tarce. Odsącz masę przez sito. Zetrzyj cebulę na tarce.\nDodaj do ziemniaków cebulę, jajka, gałkę muszkatołową oraz mini kostkę Knorr.\nWymieszaj wszystko dobrze, dodaj mąkę, aby nadać masie odpowiednią konsystencję.\nRozgrzej na patelni olej, nakładaj masę łyżką. Smaż placki z obu stron na złoty brąz i od razu podawaj.',
self.harvester_class.instructions()
)
1 change: 1 addition & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from recipe_scrapers.tests.test_nihhealthyeating import *
from recipe_scrapers.tests.test_panelinha import *
from recipe_scrapers.tests.test_paninihappy import *
from recipe_scrapers.tests.test_przepisy import *
from recipe_scrapers.tests.test_realsimple import *
from recipe_scrapers.tests.test_seriouseats import *
from recipe_scrapers.tests.test_simplyrecipes import *
Expand Down

0 comments on commit ffee963

Please sign in to comment.