recipecutter

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

README

recipe-cutter 🔪

A Page scraper to convert it into recipe schema

Test run

If you want to run the package locally and do some quick test,

update main_test.go with the website you want to hit and the schema. Just as you would using the package.

go test --args -sandbox=true

This will run all your test but it will output the code from main_test.go in your console.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ingredient

type Ingredient struct {
	Name   string
	Unit   string
	Amount string
}

Ingredient information

type IngredientSchema

type IngredientSchema struct {
	// the root element where all the ingredients will be listed
	Root string
	// the element container for each ingredient within the root
	Row string
	// if name is zero-value, it would take the text value within the row
	Name   string
	Unit   string
	Amount string
}

IngredientSchema to help drill down the list

type Recipe

type Recipe struct {
	Title         string
	Author        string
	DatePublished time.Time
	Ingredients   []Ingredient
}

TODO Move Recipe and Ingredient to a shared schema package Recipe extracted from the website base on the given schema mapping

type RecipePage

type RecipePage struct {
	URL string
	// contains filtered or unexported fields
}

RecipePage to interact with the screen scrapping

func NewRecipePage

func NewRecipePage(url string) RecipePage

NewRecipePage creates an object with colly scaffolded and ready to be used

func (RecipePage) Retrieve

func (c RecipePage) Retrieve(schemas ...Schema) (Recipe, error)

Retrieve all the page info scrapped by the given schemas. Schemas are scraped by precedence, means the last schema will override the earlier arguments

type Schema

type Schema struct {
	Title         string
	Author        string
	DatePublished string
	Ingredient    IngredientSchema
}

Schema to map css selector to the recipe properties, where key = recipe detail and value = css selector Will have matching properties to `Recipe` struct. If the page does not contain any of those details, an empty value (string zero-value) should be placed.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL