Skip to content

Commit

Permalink
Adds MobKitchen Scraper (#506) (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
conor-f authored Apr 1, 2022
1 parent ffd09fd commit dca8017
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ repos:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ Scrapers available for:
- `http://mindmegette.hu/ <http://mindmegette.hu/>`_
- `https://minimalistbaker.com/ <https://minimalistbaker.com/>`_
- `https://misya.info/ <https://misya.info>`_
- `https://www.mobkitchen.co.uk/ <https://www.mobkitchen.co.uk/>`_
- `https://momswithcrockpots.com/ <https://momswithcrockpots.com>`_
- `https://monsieur-cuisine.com/ <https://monsieur-cuisine.com>`_
- `http://motherthyme.com/ <http://motherthyme.com/>`_
Expand Down Expand Up @@ -314,7 +315,7 @@ Assuming you have ``>=python3.7`` installed, navigate to the directory where you
source .venv/bin/activate &&
pip install -r requirements-dev.txt &&
pre-commit install &&
python run_tests
python run_tests.py
In case you want to run a single unittest for a newly developed scraper

Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
from .mindmegette import Mindmegette
from .minimalistbaker import Minimalistbaker
from .misya import Misya
from .mobkitchen import MobKitchen
from .momswithcrockpots import MomsWithCrockPots
from .monsieurcuisine import MonsieurCuisine
from .motherthyme import MotherThyme
Expand Down Expand Up @@ -299,6 +300,7 @@
Mindmegette.host(): Mindmegette,
Minimalistbaker.host(): Minimalistbaker,
Misya.host(): Misya,
MobKitchen.host(): MobKitchen,
MomsWithCrockPots.host(): MomsWithCrockPots,
MonsieurCuisine.host(): MonsieurCuisine,
MotherThyme.host(): MotherThyme,
Expand Down
63 changes: 63 additions & 0 deletions recipe_scrapers/mobkitchen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import json
import re

from ._abstract import AbstractScraper
from ._schemaorg import SchemaOrg


class MobKitchen(AbstractScraper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

recipe_schema = None
for schema in self.soup.head.find_all("script", type="application/ld+json"):
recipe_schema = schema.find(string=re.compile('"@type":"Recipe"'))

if recipe_schema:
break

recipe_schema = json.loads(recipe_schema)

# MobKitchen don't follow the Recipe schema correctly, so this fixes
# the formatting so the Schema is parsed correctly.
for instruction in recipe_schema["recipeInstructions"]:
instruction["text"] = instruction["text"]["result"]

self.schema = SchemaOrg(recipe_schema, raw=True)

@classmethod
def host(cls):
return "mobkitchen.co.uk"

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):
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()

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

def description(self):
return self.schema.description()
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-e .
black>=21.4b2
black>=22.3.0
coverage>=4.5.1
flake8>=3.8.3
flake8-printf-formatting>=1.1.0
Expand Down
7 changes: 7 additions & 0 deletions tests/test_data/mobkitchen.testhtml

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions tests/test_mobkitchen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from recipe_scrapers.mobkitchen import MobKitchen
from tests import ScraperTest


class TestMobKitchenScraper(ScraperTest):

scraper_class = MobKitchen

def test_host(self):
self.assertEqual("mobkitchen.co.uk", self.harvester_class.host())

def test_author(self):
self.assertEqual("Mob", self.harvester_class.author())

def test_title(self):
self.assertEqual("Chilli Cheese Paratha", self.harvester_class.title())

def test_category(self):
self.assertEqual("Munchies, Comfort, Speedy", self.harvester_class.category())

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

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

def test_image(self):
self.assertEqual(
"https://mobkitchen-objects.imgix.net/recipes/9K8A6392-2.jpg?auto=format&crop=focalpoint&domain=mobkitchen-objects.imgix.net&fit=crop&fp-x=0.5&fp-y=0.5&h=827&ixlib=php-3.3.1&q=82&w=1300&s=412bb43eb2623e3afb2bebc5cc73b572",
self.harvester_class.image(),
)

def test_ingredients(self):
self.assertEqual(
[
"200g Plain Flour",
"140ml Hot Water",
"7 Garlic Cloves",
"3 Tsp Chilli Powder",
"Handful Of Coriander",
"3 Spring Onions",
"250g Mozzarella",
"250g Cheddar Cheese",
"Salt",
"Vegetable Oil",
],
self.harvester_class.ingredients(),
)

def test_instructions(self):
self.assertEqual(
"""Combine the plain flour, a pinch of salt and hot water (from the kettle) in a bowl and mix with a wooden spoon. Once it is cool enough to handle, knead the dough for 5 minutes until smooth. Pour in a tablespoon of oil and knead through. Cover and rest for 10 minutes
Meanwhile, prepare the garlic chilli oil. Grate the garlic into a small microwaveable bowl with the chilli powder, ¼ teaspoon salt and 2 tablespoons of oil. Microwave for 1 minute to soften and cook the garlic.
Roughly chop your coriander and finely slice your spring onions.
Divide the dough into quarters, and then the quarters into halves to form eight even balls.
Roll two balls into large circles about 2mm thick so they are about the same size. Spread ½ a teaspoon of the chilli garlic paste on to one circle, sprinkle on a handful of shredded mozzarella and shredded cheddar. Sprinkle on your coriander and spring onions, then press a second dough circle on top – you can use some water along the edges to help it stick if you need it too
Heat up a frying pan and pour in a small glug of oil. Slap on the paratha and cook on a high heat on both sides for 2 minutes. Flip using a large spatula.
Cut into quarters and serve whilst still hot and oozing with cheese.""",
self.harvester_class.instructions(),
)

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

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

def test_description(self):
self.assertEqual(
"This Indian snack is oozing with molten cheese and chilli garlicky goodness. They will be demolished in seconds, I can promise you that. Seema x",
self.harvester_class.description(),
)

0 comments on commit dca8017

Please sign in to comment.