Skip to content

Commit ffee963

Browse files
pzurakowskihhursev
authored andcommitted
Added support for przepisy.pl
1 parent dbb63da commit ffee963

File tree

6 files changed

+1215
-0
lines changed

6 files changed

+1215
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Scrapers available for:
8484
- `http://mybakingaddiction.com/ <http://mybakingaddiction.com>`_
8585
- `https://panelinha.com.br/ <https://panelinha.com.br>`_
8686
- `http://paninihappy.com/ <http://paninihappy.com>`_
87+
- `http://przepisy.pl/ <http://przepisy.pl>`_
8788
- `http://realsimple.com/ <http://www.realsimple.com>`_
8889
- `https://www.seriouseats.com/ <https://www.seriouseats.com>`_
8990
- `http://simplyrecipes.com/ <http://www.simplyrecipes.co>`_

recipe_scrapers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .nihhealthyeating import NIHHealthyEating
3535
from .panelinha import Panelinha
3636
from .paninihappy import PaniniHappy
37+
from .przepisy import Przepisy
3738
from .realsimple import RealSimple
3839
from .seriouseats import SeriousEats
3940
from .simplyrecipes import SimplyRecipes
@@ -89,6 +90,7 @@
8990
NIHHealthyEating.host(): NIHHealthyEating,
9091
Panelinha.host(): Panelinha,
9192
PaniniHappy.host(): PaniniHappy,
93+
Przepisy.host(): Przepisy,
9294
RealSimple.host(): RealSimple,
9395
SeriousEats.host(): SeriousEats,
9496
SimplyRecipes.host(): SimplyRecipes,

recipe_scrapers/przepisy.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from ._abstract import AbstractScraper
2+
from ._utils import get_minutes, normalize_string, get_yields
3+
4+
5+
class Przepisy(AbstractScraper):
6+
7+
@classmethod
8+
def host(self):
9+
return 'przepisy.pl'
10+
11+
def title(self):
12+
return self.soup.find(
13+
'h1',
14+
{'class': 'title'}
15+
).get_text()
16+
17+
def total_time(self):
18+
return get_minutes(self.soup.find(
19+
'div',
20+
{'class': 'time-count'})
21+
)
22+
23+
def yields(self):
24+
return get_yields(self.soup.find(
25+
'div',
26+
{'class': 'person-count'})
27+
)
28+
29+
def ingredients(self):
30+
ingredients = self.soup.findAll(
31+
'span',
32+
{'class': 'text-bg-white'}
33+
)
34+
35+
return [
36+
normalize_string(i.get_text()) + ' ' +
37+
normalize_string(j.get_text())
38+
for i, j in zip(ingredients[0::2], ingredients[1::2])
39+
]
40+
41+
def instructions(self):
42+
instructions = self.soup.findAll(
43+
'p',
44+
{'class': 'step-info-description'}
45+
)
46+
47+
return '\n'.join([
48+
normalize_string(instruction.get_text())
49+
for instruction in instructions
50+
])

recipe_scrapers/tests/test_data/przepisy.testhtml

Lines changed: 1099 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
import unittest
3+
4+
from recipe_scrapers.przepisy import Przepisy
5+
6+
# test recipe's URL
7+
# https://www.przepisy.pl/przepis/placki-ziemniaczane
8+
9+
10+
class TestPrzepisyScraper(unittest.TestCase):
11+
def setUp(self):
12+
# tests are run from tests.py
13+
with open(os.path.join(
14+
os.path.dirname(os.path.realpath(__file__)),
15+
'test_data',
16+
'przepisy.testhtml'
17+
)) as file_opened:
18+
self.harvester_class = Przepisy(file_opened, test=True)
19+
20+
def test_host(self):
21+
self.assertEqual(
22+
'przepisy.pl',
23+
self.harvester_class.host()
24+
)
25+
26+
def test_title(self):
27+
self.assertEqual(
28+
'Placki ziemniaczane',
29+
self.harvester_class.title()
30+
)
31+
32+
def test_total_time(self):
33+
self.assertEqual(
34+
40,
35+
self.harvester_class.total_time()
36+
)
37+
38+
def test_yields(self):
39+
self.assertEqual(
40+
'8 serving(s)',
41+
self.harvester_class.yields()
42+
)
43+
44+
def test_ingredients(self):
45+
self.assertEqual(
46+
[
47+
'ziemniaki 1 kilogram',
48+
'cebula 1 sztuka',
49+
'jajka 2 sztuki',
50+
'Przyprawa w Mini kostkach Czosnek Knorr 1 sztuka',
51+
'Gałka muszkatołowa z Indonezji Knorr 1 szczypta',
52+
'sól 1 szczypta',
53+
'mąka 3 łyżki'
54+
],
55+
self.harvester_class.ingredients()
56+
)
57+
58+
def test_instructions(self):
59+
self.assertEqual(
60+
'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.',
61+
self.harvester_class.instructions()
62+
)

tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from recipe_scrapers.tests.test_nihhealthyeating import *
3434
from recipe_scrapers.tests.test_panelinha import *
3535
from recipe_scrapers.tests.test_paninihappy import *
36+
from recipe_scrapers.tests.test_przepisy import *
3637
from recipe_scrapers.tests.test_realsimple import *
3738
from recipe_scrapers.tests.test_seriouseats import *
3839
from recipe_scrapers.tests.test_simplyrecipes import *

0 commit comments

Comments
 (0)