Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for coop.se #583

Merged
merged 3 commits into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -118,6 +118,7 @@ Scrapers available for:
- `https://cookinglight.com/ <https://cookinglight.com/>`_
- `https://cookpad.com/ <https://cookpad.com/>`_
- `https://cookstr.com/ <https://cookstr.com>`_
- `https://www.coop.se/ <https://www.coop.se/`_
- `https://copykat.com/ <https://copykat.com>`_
- `https://countryliving.com/ <https://countryliving.com>`_
- `https://cucchiaio.it/ <https://cucchiaio.it>`_
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Expand Up @@ -40,6 +40,7 @@
from .cookingcircle import CookingCircle
from .cookinglight import CookingLight
from .cookpad import CookPad
from .coop import Coop
from .cookstr import Cookstr
from .copykat import CopyKat
from .countryliving import CountryLiving
Expand Down Expand Up @@ -246,6 +247,7 @@
CookingCircle.host(): CookingCircle,
CookingLight.host(): CookingLight,
Cookstr.host(): Cookstr,
Coop.host(): Coop,
CopyKat.host(): CopyKat,
CountryLiving.host(): CountryLiving,
Cucchiaio.host(): Cucchiaio,
Expand Down
2 changes: 1 addition & 1 deletion recipe_scrapers/_schemaorg.py
Expand Up @@ -82,7 +82,7 @@ def category(self):
return category

def author(self):
author = self.data.get("author")
author = self.data.get("author") or self.data.get("Author")
if (
author
and isinstance(author, list)
Expand Down
51 changes: 51 additions & 0 deletions recipe_scrapers/coop.py
@@ -0,0 +1,51 @@
from ._abstract import AbstractScraper


class Coop(AbstractScraper):
@classmethod
def host(cls):
return "coop.se"

def author(self):
return self.schema.author()

def title(self):
return self.schema.title()

def category(self):
return self.schema.category()

def cook_time(self):
return self.schema.cook_time()

def yields(self):
return self.schema.yields()

def image(self):
image = self.schema.image()
if image is None or image == '':
image = self.schema.data.get("image")
if (
image
and isinstance(image, list)
and len(image) >= 1
and isinstance(image[0], str)
and image[0].startswith("//")
):
image = "https:" + image[0]
return image

def ingredients(self):
return self.schema.ingredients()

def instructions(self):
return self.schema.instructions()

def ratings(self):
return self.schema.ratings()

def cuisine(self):
return self.schema.cuisine()

def description(self):
return self.schema.description()
64 changes: 64 additions & 0 deletions tests/test_coop.py
@@ -0,0 +1,64 @@
from recipe_scrapers.coop import Coop
from tests import ScraperTest


class TestCoopScraper(ScraperTest):

scraper_class = Coop

def test_host(self):
self.assertEqual("coop.se", self.harvester_class.host())

def test_author(self):
self.assertEqual("Sara Begner och Ulrika Brydling", self.harvester_class.author())

def test_title(self):
self.assertEqual("Grillat kött med lime- och chilismör", self.harvester_class.title())

def test_category(self):
self.assertEqual("Huvudrätt", self.harvester_class.category())

def test_cook_time(self):
self.assertEqual(15, self.harvester_class.cook_time())

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

def test_yields(self):
self.assertEqual("4 servings", self.harvester_class.yields())

def test_image(self):
self.assertEqual("https://res.cloudinary.com/coopsverige/image/upload/w_1200,h_1200/v1651049395/cloud/251336.jpg", self.harvester_class.image())

def test_ingredients(self):
self.assertEqual(
[
'600.0 g flapsteak, flankstek, entrecôte eller mörad högrev',
'1.0 tsk flingsalt',
'100.0 g rumsvarmt smör',
'1.0 röd chili, skivad',
'2.0 lime',
'4.0 hjärtsalladshuvud',
'0.0 flingsalt',
'0.0 grovmalen svartpeppar'
],
self.harvester_class.ingredients()
)

def test_instructions(self):
self.assertEqual(
"""Tänd grillen med kol/briketter på ena sidan. Salta köttet. Vispa smöret fluffigt och smaksätt med chili och finrivet skal av 1 lime.\nVid fin glöd, grilla köttet direkt över värmen ca 1–2 min på varje sida. Köttet ska få fin yta och en innertemp på 52–55°. Låt vila 5 min.\nDela lime och hjärtsallad och grilla ca 5 min. Skär köttet i skivor, strö över flingsalt och svartpeppar och servera med hjärtsallad, smör och pressad lime.""",
self.harvester_class.instructions()
)

def test_ratings(self):
self.assertEqual(4.71, self.harvester_class.ratings())

def test_cuisine(self):
self.assertEqual("Mer Smak", self.harvester_class.cuisine())

def test_description(self):
self.assertEqual(
"Grillat kött som toppas med ett smakrikt smör på chili och pressad lime. Servera med grillad hjärtsallad.",
self.harvester_class.description()
)