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 americastestkitchen.com #1060

Merged
merged 10 commits into from
Apr 22, 2024
4 changes: 4 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .altonbrown import AltonBrown
from .amazingribs import AmazingRibs
from .ambitiouskitchen import AmbitiousKitchen
from .americastestkitchen import AmericasTestKitchen
from .archanaskitchen import ArchanasKitchen
from .argiro import Argiro
from .arla import Arla
Expand Down Expand Up @@ -332,6 +333,9 @@
AltonBrown.host(): AltonBrown,
AmazingRibs.host(): AmazingRibs,
AmbitiousKitchen.host(): AmbitiousKitchen,
AmericasTestKitchen.host(): AmericasTestKitchen,
AmericasTestKitchen.host(domain="cooksillustrated.com"): AmericasTestKitchen,
AmericasTestKitchen.host(domain="cookscountry.com"): AmericasTestKitchen,
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
ArchanasKitchen.host(): ArchanasKitchen,
Argiro.host(): Argiro,
Arla.host(): Arla,
Expand Down
59 changes: 59 additions & 0 deletions recipe_scrapers/americastestkitchen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# mypy: allow-untyped-defs

import functools
import json
import re

from ._abstract import AbstractScraper
from ._utils import get_minutes, normalize_string


class AmericasTestKitchen(AbstractScraper):

@classmethod
def host(cls, domain="americastestkitchen.com"):
return domain

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

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

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

def total_time(self):
return get_minutes(self._get_additional_details.get("recipeTimeNote"))

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

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

def instructions(self): # add headnote
if headnote := self._get_additional_details.get("headnote"):
# Ideally this would use HTMLTagStripperPlugin, but I'm not sure how to invoke it here
headnote = f"Note: {normalize_string(re.sub(r'<.*?>', '', headnote))}\n"
else:
headnote = ""
return headnote + self.schema.instructions()

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

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

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

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

@functools.cached_property
def _get_additional_details(self):
j = json.loads(self.soup.find(type="application/json").string)
name = list(j["props"]["initialState"]["content"]["documents"])[0]
return j["props"]["initialState"]["content"]["documents"][name]
49 changes: 49 additions & 0 deletions tests/test_data/americastestkitchen.com/americastestkitchen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"author": "America's Test Kitchen",
"canonical_url": "https://www.americastestkitchen.com/recipes/13980-instant-pot-mussels-with-fennel-and-leeks",
"category": "Main Courses, Weeknight",
"description": "Your Instant Pot is actually a great place to cook seafood.",
"host": "americastestkitchen.com",
"image": "https://res.cloudinary.com/hksqkdlah/image/upload/ar_1:1,c_fill,dpr_2.0,f_auto,fl_lossy.progressive.strip_profile,g_faces:auto,q_auto:low,w_150/SFS_Mussels-with-Fennel-and-Leeks_6_5_xjdlfl",
"ingredient_groups": [
{
"ingredients": [
"1 tablespoon, extra-virgin olive oil, plus extra for drizzling",
"1 , fennel bulb, 1 tablespoon fronds minced, stalks discarded, bulb halved, cored, and sliced thin",
"1 , leek, ends trimmed, leek halved lengthwise, sliced 1 inch thick, and washed thoroughly",
"4 , garlic cloves, minced",
"3 sprigs, fresh thyme",
"1/4 teaspoon, red pepper flakes",
"1/2 cup, dry white wine",
"3 pounds, mussels, scrubbed and debearded"
],
"purpose": null
}
],
"ingredients": [
"1 tablespoon, extra-virgin olive oil, plus extra for drizzling",
"1 , fennel bulb, 1 tablespoon fronds minced, stalks discarded, bulb halved, cored, and sliced thin",
"1 , leek, ends trimmed, leek halved lengthwise, sliced 1 inch thick, and washed thoroughly",
"4 , garlic cloves, minced",
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
"3 sprigs, fresh thyme",
"1/4 teaspoon, red pepper flakes",
"1/2 cup, dry white wine",
"3 pounds, mussels, scrubbed and debearded"
],
"instructions": "Note: Discard any raw mussels with an unpleasant odor or with a cracked or broken shell that won't close. To prevent the mussels from overcooking, be sure to turn off the Instant Pot as soon as it reaches pressure. Serve with crusty bread, if desired.\nUsing highest sauté function, heat oil in Instant Pot until shimmering. Add fennel and leek and cook until softened, about 5 minutes. Stir in garlic, thyme sprigs, and pepper flakes and cook until fragrant, about 30 seconds. Stir in wine, then add mussels.\nLock lid in place and close pressure release valve. Select high pressure cook function and set cook time for 0 minutes. Once Instant Pot has reached pressure, immediately turn off pot and quick-release pressure. Carefully remove lid, allowing steam to escape away from you.\nDiscard thyme sprigs and any mussels that have not opened. Transfer mussels to individual serving bowls, sprinkle with fennel fronds, and drizzle with extra oil. Serve.",
"instructions_list": [
"Note: Discard any raw mussels with an unpleasant odor or with a cracked or broken shell that won't close. To prevent the mussels from overcooking, be sure to turn off the Instant Pot as soon as it reaches pressure. Serve with crusty bread, if desired.",
"Using highest sauté function, heat oil in Instant Pot until shimmering. Add fennel and leek and cook until softened, about 5 minutes. Stir in garlic, thyme sprigs, and pepper flakes and cook until fragrant, about 30 seconds. Stir in wine, then add mussels.",
"Lock lid in place and close pressure release valve. Select high pressure cook function and set cook time for 0 minutes. Once Instant Pot has reached pressure, immediately turn off pot and quick-release pressure. Carefully remove lid, allowing steam to escape away from you.",
"Discard thyme sprigs and any mussels that have not opened. Transfer mussels to individual serving bowls, sprinkle with fennel fronds, and drizzle with extra oil. Serve."
],
"language": "en",
"nutrients": {
"calories": "1540 calories"
},
"ratings": 5.0,
"site_name": null,
"title": "Instant Pot Mussels with Fennel and Leeks",
"total_time": 45.0,
"yields": "4 servings"
}
Loading