Skip to content

Commit

Permalink
Raise an exception when field information is not provided by a host
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Oct 28, 2022
1 parent c8ca5f6 commit 3ea825e
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion recipe_scrapers/_abstract.py
@@ -1,4 +1,4 @@
# mypy: allow-untyped-defs
# mypy: disallow_untyped_defs=False

from abc import ABC, abstractmethod
from collections import OrderedDict
Expand Down
1 change: 1 addition & 0 deletions recipe_scrapers/_exceptions.py
@@ -1,4 +1,5 @@
# mypy: disallow_untyped_defs=False

class RecipeScrapersExceptions(Exception):
def __init__(self, message):
self.message = message
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/coop.py
@@ -1,4 +1,5 @@
# mypy: disallow_untyped_defs=False

from ._abstract import AbstractScraper


Expand All @@ -17,8 +18,7 @@ def category(self):
return self.schema.category()

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
return self.schema.total_time()

def cook_time(self):
return self.schema.cook_time()
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/davidlebovitz.py
@@ -1,5 +1,7 @@
# mypy: disallow_untyped_defs=False

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions


class DavidLebovitz(AbstractScraper):
Expand All @@ -14,8 +16,7 @@ def title(self):
return self.schema.title()

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def image(self):
return self.schema.image()
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/farmhousedelivery.py
@@ -1,9 +1,11 @@
# mypy: disallow_untyped_defs=False

import re

from bs4 import Tag

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions
from ._utils import normalize_string

"""
Expand All @@ -21,8 +23,7 @@ def title(self):
return self.soup.find("h1", {"class": "entry-title"}).get_text(strip=True)

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def ingredients(self):
# Style 1
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/fredriksfikaallas.py
@@ -1,7 +1,9 @@
# mypy: disallow_untyped_defs=False

import re

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions


class FredriksFikaAllas(AbstractScraper):
Expand All @@ -25,8 +27,7 @@ def category(self):
)

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def image(self):
return self.schema.image()
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/kuchniadomowa.py
@@ -1,5 +1,7 @@
# mypy: disallow_untyped_defs=False

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions


class KuchniaDomowa(AbstractScraper):
Expand All @@ -11,8 +13,7 @@ def title(self):
return self.soup.find("h2").get_text().strip()

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
return self.schema.total_time()

def image(self):
urls = self.soup.findAll("img", {"class": "article-img", "id": "article-img-1"})
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/kwestiasmaku.py
@@ -1,5 +1,7 @@
# mypy: disallow_untyped_defs=False

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions
from ._utils import get_yields, normalize_string


Expand All @@ -17,8 +19,7 @@ def title(self):
return normalize_string(self.soup.find("div", {"itemprop": "name"}).get_text())

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def yields(self):
return get_yields(
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/maangchi.py
@@ -1,6 +1,7 @@
# mypy: allow-untyped-defs

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions
from ._utils import normalize_string


Expand All @@ -19,8 +20,7 @@ def category(self):
return self.schema.category()

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def yields(self):
return self.schema.yields()
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/mykitchen101.py
@@ -1,9 +1,11 @@
# mypy: disallow_untyped_defs=False

import re

from bs4 import BeautifulSoup

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions
from ._utils import get_yields, normalize_string


Expand All @@ -19,8 +21,7 @@ def title(self):
return self.soup.find("h1", {"class": "entry-title"}).get_text()

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def yields(self):
return get_yields(self.soup.find("p", string=re.compile("分量:")).get_text())
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/mykitchen101en.py
@@ -1,9 +1,11 @@
# mypy: disallow_untyped_defs=False

import re

from bs4 import BeautifulSoup

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions
from ._utils import get_yields, normalize_string


Expand All @@ -19,8 +21,7 @@ def title(self):
return self.soup.find("h1", {"class": "entry-title"}).get_text()

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def yields(self):
return get_yields(self.soup.find("p", string=re.compile("Yields: ")).get_text())
Expand Down
5 changes: 3 additions & 2 deletions recipe_scrapers/owenhan.py
@@ -1,5 +1,7 @@
# mypy: disallow_untyped_defs=False

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions


class OwenHan(AbstractScraper):
Expand All @@ -14,8 +16,7 @@ def title(self):
return self.soup.find("h1", {"class": "entry-title"}).text

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def image(self):
return self.schema.image()
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/rosannapansino.py
@@ -1,6 +1,7 @@
# mypy: allow-untyped-defs

from ._abstract import AbstractScraper
from ._exceptions import RecipeScrapersExceptions
from ._utils import normalize_string


Expand All @@ -13,8 +14,7 @@ def title(self):
return self.soup.find("meta", {"property": "og:title"})["content"]

def total_time(self):
# TODO: add implementation
raise NotImplementedError("This should be implemented.")
raise RecipeScrapersExceptions(f"{self.host} does not provide time information.")

def image(self):
return self.schema.image()
Expand Down
4 changes: 4 additions & 0 deletions tests/test_davidlebovitz.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.davidlebovitz import DavidLebovitz
from tests import ScraperTest

Expand All @@ -15,6 +16,9 @@ def test_author(self):
def test_title(self):
self.assertEqual("Faux Gras", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

def test_image(self):
self.assertEqual(
"https://www.davidlebovitz.com/wp-content/uploads/2015/06/Faux-Gras-Lentil-Pate-8.jpg",
Expand Down
4 changes: 4 additions & 0 deletions tests/test_farmhousedelivery_1.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.farmhousedelivery import FarmhouseDelivery
from tests import ScraperTest

Expand All @@ -19,6 +20,9 @@ def test_canonical_url(self):
def test_title(self):
self.assertEqual("Green Shakshuka", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

def test_ingredients(self):
self.assertEqual(
[
Expand Down
4 changes: 4 additions & 0 deletions tests/test_farmhousedelivery_2.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.farmhousedelivery import FarmhouseDelivery
from tests import ScraperTest

Expand All @@ -22,6 +23,9 @@ def test_title(self):
self.harvester_class.title(),
)

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

def test_ingredients(self):
self.assertEqual(
[
Expand Down
4 changes: 4 additions & 0 deletions tests/test_fredriksfikaallas.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.fredriksfikaallas import FredriksFikaAllas
from tests import ScraperTest

Expand All @@ -15,6 +16,9 @@ def test_author(self):
def test_title(self):
self.assertEqual("Mormors bästa tekakor", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

def test_category(self):
self.assertEqual("Fredriks bröd", self.harvester_class.category())

Expand Down
4 changes: 4 additions & 0 deletions tests/test_mykitchen101.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.mykitchen101 import MyKitchen101
from tests import ScraperTest

Expand All @@ -15,6 +16,9 @@ def test_author(self):
def test_title(self):
self.assertEqual("古早味迷你烤鸡蛋糕", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

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

Expand Down
4 changes: 4 additions & 0 deletions tests/test_mykitchen101en.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.mykitchen101en import MyKitchen101en
from tests import ScraperTest

Expand All @@ -15,6 +16,9 @@ def test_author(self):
def test_title(self):
self.assertEqual("Mini Baked Egg Sponge Cakes", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

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

Expand Down
4 changes: 4 additions & 0 deletions tests/test_owenhan.py
@@ -1,3 +1,4 @@
from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.owenhan import OwenHan
from tests import ScraperTest

Expand All @@ -15,6 +16,9 @@ def test_host(self):
def test_title(self):
self.assertEqual("Chicken Bacon Ranch", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

def test_image(self):
self.assertEqual(
"http://static1.squarespace.com/static/627be79397093e2de753b260/627c408602fed77ca384eb11/63120c4090e9bf706973d712/1662127792157/IMG_2037.jpg?format=1500w",
Expand Down
4 changes: 4 additions & 0 deletions tests/test_rosannapansino.py
@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs

from recipe_scrapers._exceptions import RecipeScrapersExceptions
from recipe_scrapers.rosannapansino import RosannaPansino
from tests import ScraperTest

Expand All @@ -14,6 +15,9 @@ def test_host(self):
def test_title(self):
self.assertEqual("Marshmallow Fondant", self.harvester_class.title())

def test_total_time(self):
self.assertRaises(RecipeScrapersExceptions, self.harvester_class.total_time)

def test_image(self):
self.assertEqual(
"http://cdn.shopify.com/s/files/1/0163/5948/9636/articles/1Y6A6281_grande.jpg?v=1567109086",
Expand Down

0 comments on commit 3ea825e

Please sign in to comment.