menuizer/index.js
2019-09-20 23:49:04 +01:00

275 lines
16 KiB
JavaScript

const sentence = require('to-sentence-case');
const UltraSES = require('ultrases');
const dateFormat = require('dateformat');
const pug = require('pug');
const cron = require('node-cron');
const LocalStorage = require('node-localstorage').LocalStorage;
const logger = require('log4js').getLogger('menuizer');
logger.level = 'debug';
// {'name':'', 'url':''
localStorage = new LocalStorage('./scratch');
const email = require('smtp-email-sender')({
'host': 'mail.caliban.io',
'port': '465',
'auth': {
'user': 'aida@caliban.io',
'pass': 'WaF#E+5am7.)\\csD',
'type': 'LOGIN' // PLAIN, LOGIN, MD5 etc...
},
'secure': 'secure'
});
const mailer = new UltraSES({
'aws': {
'accessKeyId': 'AKIAJWJS75F7WNCGK64A',
'secretAccessKey': '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',
'region': 'eu-west-1'
}, 'defaults': {
'from': 'Martin Donnelly <martind2000@gmail.com>'
}
});
const menu = [
{
'name': 'Asian pepper steak crock pot recipe',
'url': 'https://www.marksdailyapple.com/asian-pepper-steak-crock-pot-recipe/#axzz29jTSubMo'
},
{ 'name': 'Beef burgandy', 'url': 'http://www.marksdailyapple.com/beef-burgundy-recipe/#axzz29jTSubMo' },
{ 'name': 'italian sausage meatballs', 'url': 'http://www.marksdailyapple.com/primal-meatballs/#axzz29jTSubMo' },
{ 'name': 'frittata aleta', 'url': 'http://www.marksdailyapple.com/frittata-aleta/#axzz29jTSubMo' },
{ 'name': 'garlic pulled pork', 'url': 'http://www.marksdailyapple.com/garlic-pulled-pork/#axzz29jTSubMo' },
{ 'name': 'crock pot pork stuffed peppers', 'url': 'http://www.marksdailyapple.com/crock-pot-pork-stuffed-peppers/#axzz29jTSubMo' },
{
'name': 'sesame chicken with "rice"',
'url': 'http://www.marksdailyapple.com/sesame-chicken-and-rice-with-fiery-ginger-and-chile-sauce/#axzz29jTSubMo'
},
{
'name': 'crispy nut and herb fried chicken',
'url': 'http://www.marksdailyapple.com/crispy-nut-and-herb-fried-chicken-with-creamy-avocado/#axzz29jTSubMo'
},
{ 'name': 'spicy chicken and bacon poppers', 'url': 'http://www.marksdailyapple.com/spicy-chicken-and-bacon-poppers/#axzz29jTSubMo' },
{ 'name': 'butter chicken in silky sauce', 'url': 'http://www.marksdailyapple.com/butter-chicken-in-a-silky-sauce/#axzz29jTSubMo' },
{ 'name': 'steak', 'url': 'https://www.farmison.com/community/recipe/how-to-cook-your-beef-fillet-steak' },
{
'name': 'hazelnut crusted chicken',
'url': 'http://www.marksdailyapple.com/hazelnut-crusted-chicken-with-stealth-coconut/#axzz29jTSubMo'
},
{ 'name': 'vegetable latkes', 'url': 'http://www.marksdailyapple.com/vegetable-latkes/#axzz29jTSubMo' },
{ 'name': 'beef stew', 'url': 'http://www.marksdailyapple.com/beef-stew-and-chicken-soup-in-35-minutes-or-less/#axzz29jTSubMo' },
{ 'name': 'chicken soup', 'url': 'http://www.marksdailyapple.com/beef-stew-and-chicken-soup-in-35-minutes-or-less/#axzz29jTSubMo' },
{ 'name': 'sausage patties', 'url': 'https://www.tasteslovely.com/homemade-paleo-breakfast-sausage-patties/' },
{ 'name': 'primal tex mex torillas', 'url': 'http://www.marksdailyapple.com/primal-tex-mex-tortillas-and-taco-seasoning/#axzz29jTSubMo' },
{ 'name': 'primal texas chili', 'url': 'http://www.marksdailyapple.com/primal-texas-chili/#axzz29jTSubMo' },
{ 'name': 'moroccan burgers', 'url': 'https://sarahfragoso.com/moroccan-burgers-and-beet-salad/' },
{ 'name': 'paleo spaghetti', 'url': 'https://paleoleap.com/paleo-spaghetti/' },
{ 'name': 'primal chicken tikka masala', 'url': 'http://www.marksdailyapple.com/primal-chicken-tikka-masala/#axzz29jTSubMo' },
{ 'name': 'butter stuffed chicken kiev', 'url': 'http://www.marksdailyapple.com/butter-stuffed-chicken-kiev/#axzz29jTSubMo' },
{ 'name': 'tender lemon parsley brisket', 'url': 'http://www.marksdailyapple.com/tender-lemon-parsley-brisket/#axzz29jTSubMo' },
{ 'name': 'banh mi salad', 'url': 'http://www.marksdailyapple.com/banh-mi-salad/#axzz29jTSubMo' },
{ 'name': 'taco bowl crispy kale', 'url': 'http://www.marksdailyapple.com/taco-bowl-with-crispy-kale-chips/#axzz29jTSubMo' },
{ 'name': 'lime and basil kebabs', 'url': 'http://www.marksdailyapple.com/lime-and-basil-beef-kebabs/#axzz29jTSubMo' },
{ 'name': 'sun dried tomato meatballs', 'url': 'https://sarahfragoso.com/sun-dried-tomato-meatballs-with-creamy-pesto/' },
{ 'name': 'slow cooked coconut ginger pork', 'url': 'http://www.marksdailyapple.com/slow-cooked-coconut-ginger-pork/#axzz29jTSubMo' },
{ 'name': 'balsamic glazed drumsticks', 'url': 'http://www.marksdailyapple.com/balsamic-glazed-drumsticks/#axzz29jTSubMo' },
{ 'name': 'herb chicken cooked under a brick', 'url': 'http://www.marksdailyapple.com/herb-chicken-cooked-under-a-brick/#axzz29jTSubMo' },
{ 'name': 'pork stuffed jalapeno peppers', 'url': 'http://www.marksdailyapple.com/pork-stuffed-jalapeno-peppers/#axzz29jTSubMo' },
{
'name': 'spiced pork butternut squash',
'url': 'http://www.marksdailyapple.com/spiced-pork-and-butternut-squash-with-sage/#axzz29jTSubMo'
},
{ 'name': 'shakshuka', 'url': 'http://www.marksdailyapple.com/shakshuka-eggs-poached-in-spicy-tomato-sauce/#axzz29jTSubMo' },
{ 'name': 'grilled lime chicken', 'url': 'http://www.simplyrecipes.com/recipes/grilled_lime_chicken_with_black_bean_sauce/' },
{ 'name': 'eggs benadict burger', 'url': 'https://paleoleap.com/eggs-benedict-burgers/' },
{
'name': 'asian marinated steaks',
'url': 'https://web.archive.org/web/20120330045230/http://www.paleotable.com/2011/01/asian-marinated-steaks.html'
},
{ 'name': 'tango burgers', 'url': 'https://web.archive.org/web/20120127101048/http://www.paleotable.com/2011/01/tango-burgers.html' },
{ 'name': 'meatza', 'url': 'https://web.archive.org/web/20120118062740/http://www.paleotable.com/2011/02/meatza.html' },
{
'name': 'baked chicken with roasted tomatos',
'url': 'https://web.archive.org/web/20120125102938/http://www.paleotable.com/2011/01/baked-chicken-with-roasted-tomatoes.html'
},
{
'name': 'blackened chicken',
'url': 'https://web.archive.org/web/20120420232533/http://www.paleotable.com/2011/02/blackened-chicken.html'
},
{ 'name': 'breaded baked chicken', 'url': 'https://www.tastesoflizzyt.com/paleo-baked-chicken/' },
{
'name': 'chicken and avocado tostadas',
'url': 'https://web.archive.org/web/20120707073826/http://www.paleotable.com/2011/03/chicken-and-avocado-tostadas.html'
},
{
'name': 'sausages and pepperonata',
'url': 'https://web.archive.org/web/20120707071653/http://www.paleotable.com/2011/01/sausages-and-pepperonata.html'
},
{ 'name': 'Mediterranean Beef Stew with Green Olive Pesto', 'url': 'http://www.health-bent.com/soups/paleo-mediterranean-beef-stew' },
{
'name': 'Beanless Chili',
'url': 'https://web.archive.org/web/20121004005636/http://www.realfoodfreaks.com/2012/04/02/chili-beanless-cuz-i-dont-eat-em/'
},
{
'name': 'Grilled Steak with Roasted Jalapeño Chimichurri',
'url': 'https://www.seriouseats.com/recipes/2012/05/ted-allens-grilled-steak-with-roasted-jalepeno.html'
},
{ 'name': 'Lime and Coconut Chicken', 'url': 'http://chaosinthekitchen.com/2009/07/lime-and-coconut-chicken/' },
{ 'name': 'BEEF AND VEGETABLE CHILI', 'url': 'http://www.paleoplan.com/2011/10-12/steak-and-vegetable-chili/' },
{
'name': 'PORK LOIN WITH PEPPERS, MUSHROOMS AND ONIONS',
'url': 'https://www.paleoplan.com/2010/02-23/pork-loin-with-peppers-mushrooms-n-onions/'
},
{ 'name': 'Melt In Your Mouth Slow Cooker Beef Brisket', 'url': 'https://paleogrubs.com/beef-brisket-recipe' },
{ 'name': 'Yummy Sweet Potato Gnocchi', 'url': 'https://paleogrubs.com/sweet-potato-gnocchi-recipe' },
{ 'name': 'Simple Beef and Broccoli Stir Fry', 'url': 'https://paleogrubs.com/beef-and-broccoli-recipe' },
{ 'name': 'Crockpot Balsamic Roast Beef', 'url': 'https://www.primallyinspired.com/crockpot-balsamic-roast-beef/' },
{ 'name': 'Quick & Easy Crock Pot Chili', 'url': 'https://www.healthstartsinthekitchen.com/2014/01/04/quick-crock-pot-chili/' },
{ 'name': 'Tom Kha Gai -- Thai Coconut Soup', 'url': 'https://www.angsarap.net/2012/03/08/tom-kha-gai/' },
{ 'name': 'Roasted, Herbed Beef Tenderloin Recipe', 'url': 'https://www.chowhound.com/recipes/roasted-herbed-beef-tenderloin-30901' },
{
'name': 'Chorizo Carbonara',
'url': 'https://www.jamieoliver.com/recipes/pasta-recipes/chorizo-carbonara-with-catalan-market-salad/#1EmLf9RiqepY4Z95.97'
},
{ 'name': 'Roasted Tomato Soup with Fresh Basil', 'url': 'https://civilizedcaveman.com/recipes/soups/roasted-tomato-soup/' },
{ 'name': 'swedish meatballs', 'url': 'https://www.paleorunningmomma.com/paleo-swedish-meatballs-whole30/' },
{ 'name': 'Tom Yum Gai - hot and sour soup', 'url': 'http://angsarap.net/2013/08/07/tom-yum-gai/' },
{ 'name': 'Coconut Lime Chicken Soup', 'url': 'https://paleoleap.com/coconut-lime-chicken-soup/' },
{ 'name': 'Hungarian Beef Goulash', 'url': 'https://paleoleap.com/hungarian-beef-goulash/' },
{ 'name': 'Beef Bourguignon', 'url': 'http://paleoleap.com/beef-bourguignon/' },
{ 'name': 'Minted pesto chicken stir-fry', 'url': 'http://paleoleap.com/quick-and-easy-paleo-stir-fries/' },
{ 'name': 'Coconut curry stir-fry', 'url': 'http://paleoleap.com/quick-and-easy-paleo-stir-fries/' },
{ 'name': 'Citrus beef salad stir-fry', 'url': 'http://paleoleap.com/quick-and-easy-paleo-stir-fries/' },
{ 'name': 'Basil and chilli beef stir-fry', 'url': 'http://paleoleap.com/quick-and-easy-paleo-stir-fries/' },
{ 'name': 'a normal chicken stir fry', 'url': '' },
{ 'name': 'hunters chicken ( chicken wrapped in bacon / pancetta )', 'url': '' },
{ 'name': 'Caribbean Pork Chops with Mango Salsa | Paleo Grubs', 'url': 'https://paleogrubs.com/caribbean-pork-chops-recipe' },
{ 'name': 'Paleo Pork Tenderloin with Fig and Balsamic Glaze', 'url': 'http://paleogrubs.com/balsamic-pork-tenderloin-recipe' },
{ 'name': 'Chicken Cordon-Bacon', 'url': 'https://fastpaleo.com/recipe/bacon-wrapped-chicken-cordon-bleu/' },
{ 'name': 'Grilled Tandoori Chicken', 'url': 'http://cookingweekends.blogspot.com/2012/05/grilled-tandoori-chicken.html' },
{ 'name': 'Stuffed Chicken Breast (paleo and grain free)', 'url': 'http://www.cavegirlcuisine.com/recipes/stuffed-chicken-breast/' },
{ 'name': 'Lemon Chicken Breast Recipe', 'url': 'https://www.everydaymaven.com/lemon-chicken-breast/' },
{
'name': 'Grilled Lemon Garlic Rosemary Chicken Breasts',
'url': 'https://www.phoenixhelix.com/2013/07/21/grilled-lemon-garlic-rosemary-chicken-breasts/'
},
{
'name': 'Paleo Spicy Mustard Crockpot Chicken',
'url': 'https://www.plaidandpaleo.com/2013/10/paleo-spicy-mustard-crockpot-chicken.html'
},
{ 'name': 'Creamy Paleo Chicken Skillet', 'url': 'http://paleogrubs.com/skillet-chicken-recipe' },
{ 'name': 'Sweet and Savory Moroccan Chicken', 'url': 'http://paleogrubs.com/moroccan-chicken-recipe' },
{ 'name': 'Simple and Addictive Chicken Kabobs', 'url': 'http://paleogrubs.com/chicken-kabob-recipe' },
{ 'name': 'Indian Paleo Stew with Chicken', 'url': 'http://paleogrubs.com/indian-paleo-stew-recipe' },
{
'name': 'Slow-Cooker Swedish Kalops Stew',
'url': 'https://web.archive.org/web/20130501032143/http://www.mylivingnutrition.com/2013/04/11/slow-cooker-swedish-kalops-stew/'
},
{ 'name': 'Beef, Bacon and Rum Stew', 'url': 'http://domesticsoul.com/2011/12/beef-bacon-rum-stew-recipe.html' },
{ 'name': 'Paleo Orange Cinnamon Beef Stew', 'url': 'https://thehealthyfoodie.com/orange-cinnamon-beef-stew/' },
{ 'name': 'pepper steak', 'url': 'http://paleoleap.com/pepper-steak/' },
{ 'name': 'GARLIC ROASTED COD', 'url': 'http://paleoleap.com/garlic-roasted-cod/' },
{ 'name': 'Easy Bacon-Wrapped Paleo Meatloaf Muffins', 'url': 'https://paleogrubs.com/bacon-wrapped-meatloaf-muffins' },
{ 'name': 'Easy Ground Beef Stuffed Peppers', 'url': 'https://paleogrubs.com/ground-beef-stuffed-peppers' },
{ 'name': 'Cream of Chicken Soup', 'url': 'https://paleogrubs.com/crockpot-cream-of-chicken-soup' },
{ 'name': 'balsamic grilled chicken with greek style salad', 'url': 'https://paleoleap.com/balsamic-grilled-chicken-greek-style-salad/' },
{ 'name': 'slow cooked hawaiian style kalua pork', 'url': 'https://paleoleap.com/slow-cooked-hawaiian-style-kalua-pork/' },
{ 'name': 'Sweet Thai Chili Chicken With Roasted Peppers', 'url': 'http://paleoleap.com/sweet-thai-chili-chicken-roasted-peppers/' },
{ 'name': 'Steak Ratatouille', 'url': 'http://www.jamieoliver.com/recipes/beef-recipes/grilled-steak-ratatouille-saffron-rice/' },
{ 'name': 'Slow Cooked Balsamic Pork Roast', 'url': 'https://paleoleap.com/slow-cooked-balsamic-pork-roast/' },
{ 'name': 'Seared Cod with Fresh Herb Sauce', 'url': 'http://paleoleap.com/seared-cod-fresh-herb-sauce/' },
{ 'name': 'Honey Ginger Apple Shredded Pork', 'url': 'https://paleomg.com/honey-ginger-apple-shredded-pork/' },
{ 'name': 'Orange Pineapple Pulled Pork', 'url': 'http://www.smokedngrilled.com/orange-pineapple-pulled-pork/' },
{ 'name': 'Brazilian Curry Chicken', 'url': 'https://paleomg.com/brazilian-curry-chicken/' },
{ 'name': 'Teriyaki Meatballs', 'url': 'https://paleogrubs.com/teriyaki-meatballs' },
{ 'name': 'Paleo Slow Cooker Bacon BBQ Chicken', 'url': 'https://paleogrubs.com/chicken-breast-recipes' },
{ 'name': 'Honey-Lime Grilled Chicken Skewers', 'url': 'https://paleogrubs.com/honey-lime-grilled-chicken-skewers' },
{ 'name': 'Pork Chop With Applesauce And Roasted Tomatoes', 'url': 'https://paleoleap.com/pork-chop-applesauce-roasted-tomatoes/' },
{ 'name': 'Slow Cooked Jerk Pork Tenderloin', 'url': 'https://paleoleap.com/slow-cooked-jerk-pork-tenderloin/' },
{ 'name': 'Roasted Carrot Ginger Paleo Soup', 'url': 'https://paleogrubs.com/soup-recipes' },
{ 'name': 'Slow Cooker Taco Soup', 'url': 'https://paleogrubs.com/slow-cooker-taco-soup' },
{ 'name': 'Chicken Soup - MD', 'url': 'https://paleogrubs.com/wp-content/uploads/2019/03/Homemade-Chicken-No-Noodle-Soup-1.jpg' },
{ 'name': 'Ham Soup - MD', 'url': 'https://paleogrubs.com/wp-content/uploads/2019/03/Homemade-Chicken-No-Noodle-Soup-1.jpg' },
{ 'name': 'Chicken & Chorizo - MD', 'url': 'https://paleogrubs.com/wp-content/uploads/2019/03/Homemade-Chicken-No-Noodle-Soup-1.jpg' },
{ 'name': 'Chickpea Soup - Jess', 'url': 'https://paleogrubs.com/wp-content/uploads/2019/03/Homemade-Chicken-No-Noodle-Soup-1.jpg' },
{ 'name': 'Crockpot Paleo Minestrone Soup', 'url': 'https://www.ourpaleolife.com/crockpot-paleo-minestrone-soup/' }
];
// {'name':'', 'url':''}
function sendEmail(data, newpath) {
const now = new Date();
const email = {
'to': 'martind2000@gmail.com', 'subject': `Suggestions - ${dateFormat(now, 'dddd, mmmm dS, yyyy')}`
};
const template = {
'file': `${newpath}/` + 'pug/email.jade', 'locals': data
};
mailer.sendTemplate(email, template, err => {
if (err) throw err;
logger.info('compiled template email sent');
});
}
function sendSMTP(data, newPath) {
const now = new Date();
const html = pug.renderFile(`${newPath}/` + 'pug/email.pug', data);
email({
'from': 'Aida <aida@caliban.io>',
'to': 'Aida <aida@caliban.io>',
'bcc': 'Martin <martind2000@gmail.com>, Jessica <ing.arvid@gmail.com>',
'subject': `Suggestions 🍳 - ${dateFormat(now, 'dddd, mmmm dS, yyyy')}`,
'html': html
});
}
function pugTest(data, newpath) {
logger.debug(pug.renderFile(`${newpath}/` + 'pug/email.pug', data));
}
function doJob() {
// body
const _history = localStorage.getItem('history');
let history = [];
if (_history !== null)
history = JSON.parse(_history);
const usedNumbers = [];
const suggestions = [];
const data = {};
const now = new Date();
const options = { 'weekday': 'long', 'year': 'numeric', 'month': 'long', 'day': 'numeric' };
do {
const randomnumber = Math.floor(Math.random() * menu.length);
if (usedNumbers.indexOf(randomnumber) === -1 && history.indexOf(randomnumber) === -1) {
usedNumbers.push(randomnumber);
suggestions.push(menu[randomnumber]);
history.push(randomnumber);
}
} while (usedNumbers.length < 5);
data.ts = now.toLocaleDateString('en-GB', options);
data.suggestions = suggestions;
localStorage.setItem('history', JSON.stringify(history.slice(history.length - 20)));
sendSMTP(data, './');
logger.debug(`Done:${data.ts}`);
}
(function () {
logger.info('Menuizer started');
// doJob();
}());
cron.schedule('0 8 * * 6', function () {
doJob();
return -1;
});