Skip to content

Commit

Permalink
adding tastebetterfromscratch
Browse files Browse the repository at this point in the history
  • Loading branch information
jadkins89 committed Nov 15, 2020
1 parent e45f3e1 commit be39722
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions scrapers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const domains = {
seriouseats: require("./seriouseats"),
simplyrecipes: require("./simplyrecipes"),
smittenkitchen: require("./smittenkitchen"),
tastesbetterfromscratch: require("./tastesbetterfromscratch"),
thepioneerwoman: require("./thepioneerwoman"),
therealfoodrds: require("./therealfoodrds"),
thespruceeats: require("./thespruceeats"),
Expand Down
74 changes: 74 additions & 0 deletions scrapers/tastesbetterfromscratch.js
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;
40 changes: 40 additions & 0 deletions test/constants/tastebetterfromscratchConstants.js
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"
}
};
11 changes: 11 additions & 0 deletions test/tastesbetterfromscratch.test.js
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"
);

0 comments on commit be39722

Please sign in to comment.