-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ecrax/@type_array
added support for "@type" arrays
- Loading branch information
Showing
7 changed files
with
6,060 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package custom | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/kkyr/go-recipe" | ||
"github.com/kkyr/go-recipe/internal/html/scrape/schema" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
) | ||
|
||
const AllRecipesHost = "allrecipes.com" | ||
|
||
// NewAllRecipesScraper returns a new instance of AllRecipesScraper. | ||
func NewAllRecipesScraper(doc *goquery.Document) (recipe.Scraper, error) { | ||
s, err := schema.NewRecipeScraper(doc) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create schema scraper: %w", err) | ||
} | ||
|
||
return &AllRecipesScraper{schema: s}, nil | ||
} | ||
|
||
// AllRecipesScraper is a custom recipe scraper for allrecipes.com. | ||
type AllRecipesScraper struct { | ||
schema *schema.RecipeScraper | ||
} | ||
|
||
func (m *AllRecipesScraper) Author() (string, bool) { | ||
return m.schema.Author() | ||
} | ||
|
||
func (m *AllRecipesScraper) Categories() ([]string, bool) { | ||
return m.schema.Categories() | ||
} | ||
|
||
func (m *AllRecipesScraper) CookTime() (time.Duration, bool) { | ||
return m.schema.CookTime() | ||
} | ||
|
||
func (m *AllRecipesScraper) Cuisine() ([]string, bool) { | ||
return m.schema.Cuisine() | ||
} | ||
|
||
func (m *AllRecipesScraper) Description() (string, bool) { | ||
return m.schema.Description() | ||
} | ||
|
||
func (m *AllRecipesScraper) ImageURL() (string, bool) { | ||
return m.schema.ImageURL() | ||
} | ||
|
||
func (m *AllRecipesScraper) Ingredients() ([]string, bool) { | ||
return m.schema.Ingredients() | ||
} | ||
|
||
func (m *AllRecipesScraper) Instructions() ([]string, bool) { | ||
return m.schema.Instructions() | ||
} | ||
|
||
func (m *AllRecipesScraper) Language() (string, bool) { | ||
return m.schema.Language() | ||
} | ||
|
||
func (m *AllRecipesScraper) Name() (string, bool) { | ||
return m.schema.Name() | ||
} | ||
|
||
func (m *AllRecipesScraper) Nutrition() (recipe.Nutrition, bool) { | ||
return m.schema.Nutrition() | ||
} | ||
|
||
func (m *AllRecipesScraper) PrepTime() (time.Duration, bool) { | ||
return m.schema.PrepTime() | ||
} | ||
|
||
func (m *AllRecipesScraper) SuitableDiets() ([]recipe.Diet, bool) { | ||
return m.schema.SuitableDiets() | ||
} | ||
|
||
func (m *AllRecipesScraper) TotalTime() (time.Duration, bool) { | ||
return m.schema.TotalTime() | ||
} | ||
|
||
func (m *AllRecipesScraper) Yields() (string, bool) { | ||
return m.schema.Yields() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package custom_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/kkyr/go-recipe" | ||
"github.com/kkyr/go-recipe/internal/html/scrape/custom" | ||
"github.com/kkyr/go-recipe/internal/html/scrape/test" | ||
|
||
"github.com/kkyr/assert" | ||
) | ||
|
||
func TestNewAllRecipesScraper(t *testing.T) { | ||
doc := test.ReadHTMLFileOrFail(t, custom.AllRecipesHost) | ||
|
||
scraper, err := custom.NewAllRecipesScraper(doc) | ||
assert.New(t).Require().Nil(err) | ||
|
||
scraperTest := test.Scraper{ | ||
Author: "Jackie M", | ||
Categories: nil, | ||
CookTime: 30 * time.Minute, | ||
Cuisine: nil, | ||
Description: "This marinara sauce recipe is made by blending tomatoes, parsley, garlic, and oregano before simmering with onion and white wine for amazing flavor.", | ||
ImageURL: "https://www.allrecipes.com/thmb/rAJNjIWA7FHaI4bveYdZFkCJ7oM=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/11966-best-marinara-sauce-ddmfs-137-1x1-1-a9d124d5e86d463d87fa99de61bb9f02.jpg", | ||
Ingredients: []string{"2 (14.5 ounce) cans stewed tomatoes", "1 (6 ounce) can tomato paste", "4 tablespoons chopped fresh parsley", "1 clove garlic, minced", "1 teaspoon dried oregano", "1 teaspoon salt", "0.25 teaspoon ground black pepper", "6 tablespoons olive oil", "0.33333334326744 cup finely diced onion", "0.5 cup white wine"}, | ||
Instructions: []string{"Place tomatoes, tomato paste, parsley, garlic, oregano, salt, and pepper in a food processor; blend until smooth.", "Heat oil in a large skillet over medium heat. Add onion and cook until slightly softened, about 2 minutes. Stir in blended tomato sauce and white wine.", "Simmer, stirring occasionally, until thickened, about 30 minutes."}, | ||
Language: "", | ||
Name: "Best Marinara Sauce Yet", | ||
Nutrition: recipe.Nutrition{Calories: 151, CarbohydrateGrams: 12, CholesterolMilligrams: 0, FatGrams: 11, FiberGrams: 2, ProteinGrams: 2, SaturatedFatGrams: 2, ServingSize: "", SodiumMilligrams: 685, SugarGrams: 7, TransFatGrams: 0, UnsaturatedFatGrams: 0}, | ||
PrepTime: 15 * time.Minute, | ||
SuitableDiets: nil, | ||
TotalTime: 45 * time.Minute, | ||
Yields: "8", | ||
} | ||
|
||
scraperTest.Run(t, scraper) | ||
} |
5,686 changes: 5,686 additions & 0 deletions
5,686
internal/html/scrape/custom/testdata/allrecipes.com.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.