-
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.
Merge pull request #34 from mattbloomfield/adding-3-new-sources
adding melskitchencafe, tasteofhome, therecipecritic
- Loading branch information
Showing
23 changed files
with
755 additions
and
11 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 request = require("request"); | ||
const cheerio = require("cheerio"); | ||
|
||
const RecipeSchema = require("../helpers/recipe-schema"); | ||
|
||
const gimmedelicious = url => { | ||
const Recipe = new RecipeSchema(); | ||
return new Promise((resolve, reject) => { | ||
if (!url.includes("gimmedelicious.com/")) { | ||
reject(new Error("url provided must include 'gimmedelicious.com/'")); | ||
} else { | ||
request(url, (error, response, html) => { | ||
if (!error && response.statusCode === 200) { | ||
const $ = cheerio.load(html); | ||
|
||
Recipe.image = $("meta[property='og:image']").attr("content"); | ||
Recipe.tags = ( | ||
$("meta[name='keywords']").attr("content") || "" | ||
).split(","); | ||
Recipe.name = $(".wprm-recipe-name") | ||
.text() | ||
.trim(); | ||
|
||
$(".wprm-recipe-ingredients > .wprm-recipe-ingredient").each( | ||
(i, el) => { | ||
Recipe.ingredients.push( | ||
$(el) | ||
.text() | ||
.replace(/▢/g, "") | ||
); | ||
} | ||
); | ||
|
||
$(".wprm-recipe-instruction-text").each((i, el) => { | ||
Recipe.instructions.push( | ||
$(el) | ||
.remove("img") | ||
.text() | ||
.trim() | ||
); | ||
}); | ||
|
||
Recipe.time.prep = | ||
$(".wprm-recipe-prep_time-minutes").text() + | ||
" " + | ||
$(".wprm-recipe-prep_timeunit-minutes").text(); | ||
Recipe.time.cook = | ||
$(".wprm-recipe-cook_time-minutes").text() + | ||
" " + | ||
$(".wprm-recipe-cook_timeunit-minutes").text(); | ||
Recipe.time.total = | ||
$(".wprm-recipe-total_time-minutes").text() + | ||
" " + | ||
$(".wprm-recipe-total_timeunit-minutes").text(); | ||
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); | ||
} | ||
} else { | ||
reject(new Error("No recipe found on page")); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = gimmedelicious; |
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,72 @@ | ||
const request = require("request"); | ||
const cheerio = require("cheerio"); | ||
|
||
const RecipeSchema = require("../helpers/recipe-schema"); | ||
|
||
const julieblanner = url => { | ||
const Recipe = new RecipeSchema(); | ||
return new Promise((resolve, reject) => { | ||
if (!url.includes("julieblanner.com/")) { | ||
reject(new Error("url provided must include 'julieblanner.com/'")); | ||
} else { | ||
request(url, (error, response, html) => { | ||
if (!error && response.statusCode === 200) { | ||
const $ = cheerio.load(html); | ||
|
||
Recipe.image = $("meta[property='og:image']").attr("content"); | ||
Recipe.name = $(".wprm-recipe-name") | ||
.text() | ||
.trim(); | ||
|
||
$(".wprm-recipe-ingredients > .wprm-recipe-ingredient").each( | ||
(i, el) => { | ||
Recipe.ingredients.push( | ||
$(el) | ||
.text() | ||
.replace(/(\s\s+|▢)/g, " ") | ||
.trim() | ||
); | ||
} | ||
); | ||
|
||
$(".wprm-recipe-instruction-text").each((i, el) => { | ||
Recipe.instructions.push( | ||
$(el) | ||
.remove("img") | ||
.text() | ||
.trim() | ||
); | ||
}); | ||
|
||
Recipe.time.prep = $(".wprm-recipe-prep-time-label") | ||
.next() | ||
.text(); | ||
Recipe.time.cook = $(".wprm-recipe-cook-time-label") | ||
.next() | ||
.text(); | ||
Recipe.time.inactive = $(".wprm-recipe-custom-time-label") | ||
.next() | ||
.text(); | ||
Recipe.time.total = $(".wprm-recipe-total-time-label") | ||
.next() | ||
.text(); | ||
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); | ||
} | ||
} else { | ||
reject(new Error("No recipe found on page")); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = julieblanner; |
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,64 @@ | ||
const request = require("request"); | ||
const cheerio = require("cheerio"); | ||
|
||
const RecipeSchema = require("../helpers/recipe-schema"); | ||
|
||
const melskitchencafe = url => { | ||
const Recipe = new RecipeSchema(); | ||
return new Promise((resolve, reject) => { | ||
if (!url.includes("melskitchencafe.com/")) { | ||
reject(new Error("url provided must include 'melskitchencafe.com/'")); | ||
} else { | ||
request(url, (error, response, html) => { | ||
if (!error && response.statusCode === 200) { | ||
const $ = cheerio.load(html); | ||
|
||
const textTrim = el => el.text().trim(); | ||
|
||
Recipe.image = $("meta[property='og:image']").attr("content"); | ||
Recipe.name = textTrim( | ||
$(".wp-block-mv-recipe .mv-create-title-primary") | ||
); | ||
|
||
$("div.mv-create-ingredients ul li").each((i, el) => { | ||
Recipe.ingredients.push(textTrim($(el))); | ||
}); | ||
|
||
$("div.mv-create-instructions ol li").each((i, el) => { | ||
Recipe.instructions.push(textTrim($(el))); | ||
}); | ||
|
||
Recipe.time.prep = textTrim( | ||
$(".mv-create-time-prep .mv-create-time-format") | ||
); | ||
Recipe.time.cook = textTrim( | ||
$(".mv-create-time-active .mv-create-time-format") | ||
); | ||
Recipe.time.inactive = textTrim( | ||
$(".mv-create-time-additional .mv-create-time-format") | ||
); | ||
Recipe.time.total = textTrim( | ||
$(".mv-create-time-total .mv-create-time-format") | ||
); | ||
Recipe.servings = textTrim( | ||
$(".mv-create-time-yield .mv-create-time-format") | ||
); | ||
|
||
if ( | ||
!Recipe.name || | ||
!Recipe.ingredients.length || | ||
!Recipe.instructions.length | ||
) { | ||
reject(new Error("No recipe found on page")); | ||
} else { | ||
resolve(Recipe); | ||
} | ||
} else { | ||
reject(new Error("No recipe found on page")); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = melskitchencafe; |
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,63 @@ | ||
const request = require("request"); | ||
const cheerio = require("cheerio"); | ||
|
||
const RecipeSchema = require("../helpers/recipe-schema"); | ||
|
||
const tasteofhome = url => { | ||
const Recipe = new RecipeSchema(); | ||
return new Promise((resolve, reject) => { | ||
if (!url.includes("tasteofhome.com/recipes/")) { | ||
reject(new Error("url provided must include 'tasteofhome.com/recipes/'")); | ||
} else { | ||
request(url, (error, response, html) => { | ||
if (!error && response.statusCode === 200) { | ||
const $ = cheerio.load(html); | ||
|
||
Recipe.image = $("meta[property='og:image']").attr("content"); | ||
Recipe.name = $("h1.recipe-title") | ||
.text() | ||
.trim(); | ||
|
||
$("meta[property='article:tag']").each((i, el) => { | ||
Recipe.tags.push($(el).attr("content")); | ||
}); | ||
|
||
$(".recipe-ingredients__list li").each((i, el) => { | ||
Recipe.ingredients.push($(el).text()); | ||
}); | ||
|
||
$(".recipe-directions__item").each((i, el) => { | ||
Recipe.instructions.push( | ||
$(el) | ||
.text() | ||
.trim() | ||
); | ||
}); | ||
|
||
let timeStr = $(".recipe-time-yield__label-prep") | ||
.text() | ||
.split(/Bake:/g); | ||
Recipe.time.prep = timeStr[0].replace("Prep:", "").trim(); | ||
Recipe.time.cook = (timeStr[1] || "").trim(); | ||
Recipe.servings = $(".recipe-time-yield__label-servings") | ||
.text() | ||
.trim(); | ||
|
||
if ( | ||
!Recipe.name || | ||
!Recipe.ingredients.length || | ||
!Recipe.instructions.length | ||
) { | ||
reject(new Error("No recipe found on page")); | ||
} else { | ||
resolve(Recipe); | ||
} | ||
} else { | ||
reject(new Error("No recipe found on page")); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = tasteofhome; |
Oops, something went wrong.