-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 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
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,74 @@ | ||
const cheerio = require("cheerio"); | ||
|
||
const RecipeSchema = require("../helpers/recipe-schema"); | ||
const puppeteerFetch = require("../helpers/puppeteerFetch"); | ||
|
||
const tastesBetterFromScratch = url => { | ||
return new Promise(async (resolve, reject) => { | ||
if (!url.includes("tastesbetterfromscratch.com")) { | ||
reject( | ||
new Error("url provided must include 'tastesbetterfromscratch.com'") | ||
); | ||
} else { | ||
try { | ||
const html = await puppeteerFetch(url); | ||
const Recipe = new RecipeSchema(); | ||
const $ = cheerio.load(html); | ||
|
||
Recipe.image = $("meta[property='og:image']").attr("content"); | ||
Recipe.name = $(".wprm-recipe-name").text(); | ||
|
||
$(".wprm-recipe-ingredient").each((i, el) => { | ||
let amount = $(el) | ||
.find(".wprm-recipe-ingredient-amount") | ||
.text(); | ||
let unit = $(el) | ||
.find(".wprm-recipe-ingredient-unit") | ||
.text(); | ||
let name = $(el) | ||
.find(".wprm-recipe-ingredient-name") | ||
.text(); | ||
let ingredient = `${amount} ${unit} ${name}` | ||
.replace(/\s\s+/g, " ") | ||
.trim(); | ||
Recipe.ingredients.push(ingredient); | ||
}); | ||
|
||
$(".wprm-recipe-instruction").each((i, el) => { | ||
Recipe.instructions.push( | ||
$(el) | ||
.text() | ||
.replace(/\s\s+/g, "") | ||
); | ||
}); | ||
|
||
$(".wprm-recipe-time-container").each((i, el) => { | ||
let text = $(el).text(); | ||
if (text.includes("Total Time:")) { | ||
Recipe.time.total = text.replace("Total Time:", "").trim(); | ||
} else if (text.includes("Prep Time:")) { | ||
Recipe.time.prep = text.replace("Prep Time:", "").trim(); | ||
} else if (text.includes("Cook Time:")) { | ||
Recipe.time.cook = text.replace("Cook Time:", "").trim(); | ||
} | ||
}); | ||
|
||
Recipe.servings = $(".wprm-recipe-servings").text() || ""; | ||
|
||
if ( | ||
!Recipe.name || | ||
!Recipe.ingredients.length || | ||
!Recipe.instructions.length | ||
) { | ||
reject(new Error("No recipe found on page")); | ||
} else { | ||
resolve(Recipe); | ||
} | ||
} catch (error) { | ||
reject(new Error("No recipe found on page")); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = tastesBetterFromScratch; |
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,40 @@ | ||
module.exports = { | ||
testUrl: "https://tastesbetterfromscratch.com/chess-pie/", | ||
invalidUrl: "https://www.tastesbetterfromscratch.com/notarealurl", | ||
invalidDomainUrl: "www.invalid.com", | ||
nonRecipeUrl: "https://www.tastesbetterfromscratch.com/about/", | ||
expectedRecipe: { | ||
name: "Chess Pie", | ||
ingredients: [ | ||
"1/2 cup butter", | ||
"2 cups granulated sugar", | ||
"1 Tablespoon all-purpose flour", | ||
"1 Tablespoon cornmeal", | ||
"5 large or extra-large eggs", | ||
"1 cup milk", | ||
"1 teaspoon vanilla extract", | ||
"2 Tablespoons fresh squeezed lemon juice", | ||
"1 teaspoon lemon zest", | ||
"Dough for one pie crust" | ||
], | ||
instructions: [ | ||
"In a medium mixing bowl, cream the butter and sugar. Beat in the flour and cornmeal.", | ||
"Add the eggs, one at a time, beating well after each.When the egg mixture is well beaten add the milk, vanilla, lemon juice and zest beat until smooth.", | ||
"Add pie crust to 9’’ pie plate and crimp the edges. Pour in filling.", | ||
"Bake at 350 degreed F for 55-60 minutes. Check the pie after 30 minutes and place a piece of aluminum foil on top to keep it from getting too brown. (I spray the foil with a non-stick spray to keep it from sticking to the top of the pie.)", | ||
"Allow to cool for one hour before serving." | ||
], | ||
tags: [], | ||
time: { | ||
prep: "10 minutes", | ||
cook: "1 hour", | ||
active: "", | ||
inactive: "", | ||
ready: "", | ||
total: "1 hour 10 minutes" | ||
}, | ||
servings: "12", | ||
image: | ||
"https://tastesbetterfromscratch.com/wp-content/uploads/2020/11/Chess-Pie-5.jpg" | ||
} | ||
}; |
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,11 @@ | ||
"use strict"; | ||
const commonRecipeTest = require("./helpers/commonRecipeTest"); | ||
const tastesBetterFromScratch = require("../scrapers/tastesbetterfromscratch"); | ||
const Constants = require("./constants/tastebetterfromscratchConstants"); | ||
|
||
commonRecipeTest( | ||
"tastesBetterFromScratch", | ||
tastesBetterFromScratch, | ||
Constants, | ||
"tastesbetterfromscratch.com" | ||
); |