added cooksillustrated custom scraper

This commit is contained in:
smilerz
2021-04-03 11:12:23 -05:00
parent c7949edb18
commit 52df886372

View File

@@ -4,12 +4,8 @@ from recipe_scrapers._abstract import AbstractScraper
class CooksIllustrated(AbstractScraper): class CooksIllustrated(AbstractScraper):
@classmethod @classmethod
def host(cls, site='cooksillustrated'): def host(cls):
return { return "cooksillustrated.com"
'cooksillustrated': f"{site}.com",
'americastestkitchen': f"{site}.com",
'cookscountry': f"{site}.com",
}.get(site)
def title(self): def title(self):
return self.schema.title() return self.schema.title()
@@ -35,10 +31,10 @@ class CooksIllustrated(AbstractScraper):
ingredients += group['fields']['recipeIngredientItems'] ingredients += group['fields']['recipeIngredientItems']
return [ return [
"{} {} {}{}".format( "{} {} {}{}".format(
i['fields']['qty'] or '', i['fields']['qty'],
i['fields']['measurement'] or '', i['fields']['measurement'],
i['fields']['ingredient']['fields']['title'] or '', i['fields']['ingredient']['fields']['title'],
i['fields']['postText'] or '' i['fields']['postText']
) )
for i in ingredients for i in ingredients
] ]
@@ -46,14 +42,8 @@ class CooksIllustrated(AbstractScraper):
def instructions(self): def instructions(self):
if not self.recipe: if not self.recipe:
self.get_recipe() self.get_recipe()
if self.recipe.get('headnote', False): return "\n".join([self.recipe['whyThisWorks']] +
i = ['Note: ' + self.recipe.get('headnote', '')] [
else:
i = []
return "\n".join(
i
+ [self.recipe.get('whyThisWorks', '')]
+ [
instruction['fields']['content'] instruction['fields']['content']
for instruction in self.recipe['instructions'] for instruction in self.recipe['instructions']
] ]