-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for akispetretzikis.com (#509)
- Loading branch information
Hilmar Palsson
committed
Mar 15, 2022
1 parent
6441750
commit 046a6a7
Showing
5 changed files
with
195 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,85 @@ | ||
import json | ||
|
||
from ._abstract import AbstractScraper | ||
from ._exceptions import SchemaOrgException | ||
from ._utils import normalize_string | ||
|
||
|
||
class AkisPetretzikis(AbstractScraper): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.recipe_json = json.loads( | ||
self.soup.find("script", {"id": "__NEXT_DATA__"}).get_text() | ||
) | ||
|
||
@classmethod | ||
def host(cls): | ||
return "akispetretzikis.com" | ||
|
||
def author(self): | ||
return self.schema.author() | ||
|
||
def title(self): | ||
return self.schema.title() | ||
|
||
def category(self): | ||
return self.schema.category() | ||
|
||
def total_time(self): | ||
make_time = self.recipe_json["props"]["pageProps"]["ssRecipe"]["data"][ | ||
"make_time" | ||
] | ||
bake_time = self.recipe_json["props"]["pageProps"]["ssRecipe"]["data"][ | ||
"bake_time" | ||
] | ||
return make_time + bake_time | ||
|
||
def yields(self): | ||
return self.recipe_json["props"]["pageProps"]["ssRecipe"]["data"]["shares"] | ||
|
||
def image(self): | ||
return self.schema.image() | ||
|
||
def ingredients(self): | ||
ingredient_sections = self.recipe_json["props"]["pageProps"]["ssRecipe"][ | ||
"data" | ||
]["ingredient_sections"] | ||
ingredients_list = [] | ||
if len(ingredient_sections) == 0: | ||
return ingredients_list | ||
for ingredient in ingredient_sections[0]["ingredients"]: | ||
parts = [] | ||
if ingredient["quantity"]: | ||
parts.append(ingredient["quantity"]) | ||
if ingredient["unit"]: | ||
parts.append(ingredient["unit"]) | ||
parts.append(ingredient["title"]) | ||
ingredients_list.append(" ".join(parts)) | ||
return ingredients_list | ||
|
||
def instructions(self): | ||
method = self.recipe_json["props"]["pageProps"]["ssRecipe"]["data"]["method"] | ||
if len(method) == 0: | ||
return "" | ||
instructions_list = [ | ||
normalize_string(step["step"]) for step in method[0]["steps"] | ||
] | ||
return "\n".join(instructions_list) | ||
|
||
def ratings(self): | ||
average_score = self.recipe_json["props"]["pageProps"]["ssRecipe"]["data"][ | ||
"average_score" | ||
] | ||
return round(float(average_score), 2) | ||
|
||
def cuisine(self): | ||
try: | ||
return self.schema.cuisine() | ||
except SchemaOrgException: | ||
return None | ||
|
||
def description(self): | ||
return self.schema.description() | ||
|
||
def language(self): | ||
return self.recipe_json["locale"] |
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,84 @@ | ||
from recipe_scrapers.akispetretzikis import AkisPetretzikis | ||
from tests import ScraperTest | ||
|
||
|
||
class TestAkisPetretzikisScraper(ScraperTest): | ||
|
||
scraper_class = AkisPetretzikis | ||
|
||
def test_host(self): | ||
self.assertEqual("akispetretzikis.com", self.harvester_class.host()) | ||
|
||
def test_author(self): | ||
self.assertEqual("Akis Petretzikis", self.harvester_class.author()) | ||
|
||
def test_title(self): | ||
self.assertEqual("Lemon chicken with artichokes", self.harvester_class.title()) | ||
|
||
def test_category(self): | ||
self.assertEqual(None, self.harvester_class.category()) | ||
|
||
def test_total_time(self): | ||
self.assertEqual(40, self.harvester_class.total_time()) | ||
|
||
def test_yields(self): | ||
self.assertEqual("8-10", self.harvester_class.yields()) | ||
|
||
def test_image(self): | ||
self.assertEqual( | ||
"https://d3fch0cwivr6nf.cloudfront.net/system/uploads/medium/data/15973/aginares-lemonates-me-kotopoulo.jpg", | ||
self.harvester_class.image(), | ||
) | ||
|
||
def test_ingredients(self): | ||
self.assertEqual( | ||
[ | ||
"1 1/2 kilo chicken breast fillet", | ||
"4-5 tablespoon(s) olive oil", | ||
"salt", | ||
"pepper", | ||
"50 g all-purpose flour", | ||
"2 onions", | ||
"2 clove(s) of garlic", | ||
"750 g artichokes", | ||
"80 g white wine", | ||
"lemon juice", | ||
"400 g water", | ||
"1 tablespoon(s) chicken stock pot", | ||
"2 tablespoon(s) tarragon", | ||
], | ||
self.harvester_class.ingredients(), | ||
) | ||
|
||
def test_instructions(self): | ||
self.assertEqual( | ||
"\n".join( | ||
[ | ||
"Place a frying pan over high heat and add 2-3 tablespoons olive oil.", | ||
"Cut the chicken into 2-3 cm pieces and add them into a bowl. Add salt, pepper, the flour, and mix.", | ||
"Transfer the chicken to the hot pan and sauté for 3-4 minutes until golden.", | ||
"Place a pot over high heat and add 2 tablespoons olive oil.", | ||
"Finely chop the onions and the garlic, add them to the pot, and sauté.", | ||
"Add the artichokes, the chicken, and deglaze the pot with the wine.", | ||
"Add the lemon juice, the water, the chicken stock pot, the tarragon, and mix.", | ||
"Cover with the lid and simmer over medium heat for 20-25 minutes.", | ||
"Serve with pepper, olive oil, lemon slices, and parsley.", | ||
] | ||
), | ||
self.harvester_class.instructions(), | ||
) | ||
|
||
def test_ratings(self): | ||
self.assertEqual(4.91, self.harvester_class.ratings()) | ||
|
||
def test_cuisine(self): | ||
self.assertEqual(None, self.harvester_class.cuisine()) | ||
|
||
def test_description(self): | ||
self.assertEqual( | ||
"Lemon chicken with artichokes by the Greek chef Akis Petretzikis. A quick and easy recipe for a hearty lemon chicken with tender artichokes!", | ||
self.harvester_class.description(), | ||
) | ||
|
||
def test_language(self): | ||
self.assertEqual("en", self.harvester_class.language()) |
Oops, something went wrong.