/
mobkitchen.py
61 lines (42 loc) · 1.55 KB
/
mobkitchen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# mypy: disallow_untyped_defs=False
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, domain="mobkitchen.co.uk"):
return domain
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 cuisine(self):
return self.schema.cuisine()
def description(self):
return self.schema.description()