-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbb63da
commit ffee963
Showing
6 changed files
with
1,215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
1,099
recipe_scrapers/tests/test_data/przepisy.testhtml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters