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 marmiton scraper #135

Merged
merged 2 commits into from Apr 11, 2020
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 @@ -78,6 +78,7 @@ Scrapers available for:
- `http://jamieoliver.com/ <http://www.jamieoliver.com>`_
- `https://justbento.com/ <https://justbento.com>`_
- `https://www.thekitchn.com/ <https://www.thekitchn.com/>`_
- `https://www.marmiton.org/ <https://www.marmiton.org/>`_
- `https://www.matprat.no/ <https://www.matprat.no/>`_
- `http://www.mindmegette.hu/ <http://www.mindmegette.hu/>`_
- `https://www.misya.info/ <https://www.misya.info>`_
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Expand Up @@ -27,6 +27,7 @@
from .jamieoliver import JamieOliver
from .justbento import JustBento
from .kitchn import Kitchn
from .marmiton import Marmiton
from .matprat import Matprat
from .mindmegette import Mindmegette
from .misya import Misya
Expand Down Expand Up @@ -83,6 +84,7 @@
JamieOliver.host(): JamieOliver,
JustBento.host(): JustBento,
Kitchn.host(): Kitchn,
Marmiton.host(): Marmiton,
Matprat.host(): Matprat,
Mindmegette.host(): Mindmegette,
Misya.host(): Misya,
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/_utils.py
Expand Up @@ -26,6 +26,8 @@ def get_minutes(element):
tstring = element.get_text()
if '-' in tstring:
tstring = tstring.split('-')[1] # sometimes formats are like this: '12-15 minutes'
if 'h' in tstring:
tstring = tstring.replace('h', 'hours') + 'minutes'
matched = TIME_REGEX.search(tstring)

minutes = int(matched.groupdict().get('minutes') or 0)
Expand Down
30 changes: 30 additions & 0 deletions recipe_scrapers/marmiton.py
@@ -0,0 +1,30 @@
from ._abstract import AbstractScraper


class Marmiton(AbstractScraper):

@classmethod
def host(self):
return 'marmiton.org'

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

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

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

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

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

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

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

2,735 changes: 2,735 additions & 0 deletions recipe_scrapers/tests/test_data/marmiton.testhtml

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions recipe_scrapers/tests/test_marmiton.py
@@ -0,0 +1,80 @@
import os
import unittest

from recipe_scrapers.marmiton import Marmiton


class TestMarmitonScraper(unittest.TestCase):
def setUp(self):
with open(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'test_data',
'marmiton.testhtml'
)) as file_opened:
self.harvester_class = Marmiton(file_opened, test=True)

def test_host(self):
self.assertEqual(
'marmiton.org',
self.harvester_class.host()
)

def test_title(self):
self.assertEqual(
self.harvester_class.title(),
'Ratatouille'
)

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

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

def test_ingredients(self):
self.assertCountEqual(
[
'350 g d\'aubergine',
'350 g de courgette',
'350 g de poivron de couleur rouge et vert',
'350 g d\'oignon',
'500 g de tomate bien mûres',
'3 gousses d\'ail',
'6 cuillères à soupe d\'huile d\'olive',
'1 brin de thym',
'1 feuille de laurier',
'poivre',
'sel'
],
self.harvester_class.ingredients()
)

def test_instructions(self):
return self.assertEqual(
'Coupez les tomates pelées en quartiers,\n'
'les aubergines et les courgettes en rondelles.\n'
'Emincez les poivrons en lamelles\n'
'et l\'oignon en rouelles.\n'
'Chauffez 2 cuillères à soupe d\'huile dans une poêle\n'
'et faites-y fondre les oignons et les poivrons.\n'
'Lorsqu\'ils sont tendres, ajoutez les tomates, l\'ail haché, le thym et le laurier.\n'
'Salez, poivrez et laissez mijoter doucement à couvert durant 45 minutes.\n'
'Pendant ce temps, préparez les aubergines et les courgettes. '
'Faites les cuire séparemment ou non dans l\'huile d\'olive pendant 15 minutes.\n'
'Vérifiez la cuisson des légumes pour qu\'ils ne soient plus fermes. '
'Ajoutez les alors au mélange de tomates et prolongez la cuisson sur tout petit feu pendant 10 min.\n'
'Salez et poivrez si besoin.',
self.harvester_class.instructions()
)

def test_ratings(self):
self.assertEqual(
4.8,
self.harvester_class.ratings()
)
1 change: 1 addition & 0 deletions tests.py
Expand Up @@ -26,6 +26,7 @@
from recipe_scrapers.tests.test_jamieoliver import *
from recipe_scrapers.tests.test_justbento import *
from recipe_scrapers.tests.test_kitchn import *
from recipe_scrapers.tests.test_marmiton import *
from recipe_scrapers.tests.test_matprat import *
from recipe_scrapers.tests.test_mindmegette import *
from recipe_scrapers.tests.test_misya import *
Expand Down