Meal Fatigue
10.25.2024 - Jake Rowe
As the day gets closer that I move out, I see a problem on the horizon. What am I supposed to eat? How am I supposed to come up with ideas every single day? It's a problem I see so many people have and it seems to be a major, yet unnecessary stressor. Young adults, older adults, college students, the whole bunch. "What would you like for dinner" is a sentence I hear way too much. For something so simple, I hear way too many arguments about it. I want to avoid this issue entirely, so I decided to use my programming skills to create a automated meal-picker.
I made it so that I can load any recipe into a folder in my Google Drive and it programmatically selects five of them and assigns them to a day. It also makes it easier to choose for a group because it is as simple as putting the files into a Google Drive folder which can be shared and modified by others. The list reloads every Saturday so that it will help go grocery shopping as well. Each recipe has their ingredients listed out.
Below is this week's (the week YOU are reading this) roster:
Obviously, you are welcome to use my list above for your own. However, I could understand if you have certain dietary restrictions, allergies, or even just your own preferences.
Now for the technical part. If you're not interested, feel free to skip over this!
Below is the code that makes this work. If you would like to recreate this for yourself, follow these steps:
Create a new Google Doc and add this into the Google Apps Script attached to the document.
Make changes as explained by the comments I have left in the code.
There are plenty of resources online explaning how to use Google Apps Scripts so I will not be going into detail here on the exact steps. This is a great first project with the platform however, so if you are interested at all, I recommend using this as a jumping-off point.
function onOpen(e) {
DocumentApp.getUi()
.createMenu('Meal Picker Settings')
.addItem('Re-pick dinners', 'refreshDinner')
.addToUi();
}
function refreshAll() {
refreshDinner();
}
function refreshDinner() {
// On the line below, add the folder ID of the folder you would like the program to pull recipes from.
var folder = DriveApp.getFolderById("");
var files = folder.getFiles();
var allFiles = new Array;
while (files.hasNext()) {
var file = files.next();
allFiles.push(file);
}
var randomSelection = getRandomItems(allFiles, 5);
Logger.log(randomSelection);
writeToDoc(randomSelection);
}
function getRandomItems(arr, numItems) {
const shuffledArr = arr.slice();
for (let i = shuffledArr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledArr[i], shuffledArr[j]] = [shuffledArr[j], shuffledArr[i]];
}
return shuffledArr.slice(0, numItems);
}
function writeToDoc(items) {
// Below, add the DocumentID of the Google Doc that the recipes will be inseted into.
var doc = DocumentApp.openById("");
var body = doc.getBody();
body.clear();
let date = new Date().toLocaleDateString();
body.appendParagraph("Here are the dinner picks for the week of " + date + " :");
body.appendParagraph(" ");
for (var i = 0; i < Math.min(items.length, 5); i++) {
day = ["Monday","Tuesday","Wednesday","Thursday", "Friday"];
body.appendParagraph(day[i] + ": " + items[i].getName()).setLinkUrl(items[i].getUrl());
}
body.appendParagraph(" ");
}
I hope this code helps some people out. I will certainly be using it in the future to alleviate some of the stress of having to come up with 5+ meals per week.
As always, stay tuned at https://www.jakerowe.me/articles for future projects I publish.