Skip to content

Commit

Permalink
Add support for akispetretzikis.com (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilmar Palsson committed Mar 15, 2022
1 parent 6441750 commit 046a6a7
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Scrapers available for:
- `https://claudia.abril.com.br/ <https://claudia.abril.com.br>`_
- `https://www.acouplecooks.com <https://acouplecooks.com/>`_
- `http://www.afghankitchenrecipes.com/ <http://www.afghankitchenrecipes.com/>`_
- `https://akispetretzikis.com/ <https://akispetretzikis.com/>`_
- `https://allrecipes.com/ <https://allrecipes.com/>`_
- `https://alltommat.se/ <https://alltommat.se/>`_
- `https://amazingribs.com/ <https://amazingribs.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 .abril import Abril
from .acouplecooks import ACoupleCooks
from .afghankitchenrecipes import AfghanKitchenRecipes
from .akispetretzikis import AkisPetretzikis
from .allrecipes import AllRecipes
from .alltomat import AllTomat
from .amazingribs import AmazingRibs
Expand Down Expand Up @@ -186,6 +187,7 @@
ACoupleCooks.host(): ACoupleCooks,
Abril.host(): Abril,
AfghanKitchenRecipes.host(): AfghanKitchenRecipes,
AkisPetretzikis.host(): AkisPetretzikis,
AllRecipes.host(): AllRecipes,
AllTomat.host(): AllTomat,
AmazingRibs.host(): AmazingRibs,
Expand Down
85 changes: 85 additions & 0 deletions recipe_scrapers/akispetretzikis.py
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"]
84 changes: 84 additions & 0 deletions tests/test_akispetretzikis.py
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())

0 comments on commit 046a6a7

Please sign in to comment.