A few years ago, as a way to learn something about data structures, I started coding a recipe program. I didn’t know much about anything back then and the program was rudimentary at best. I decided to tackle that again today. This is an intractable problem, however. Sure, you can search for recipes online, but I want to be able to know if I can make something with what I have on hand. So I want to keep track of my ingredients in my kitchen and have a collection of recipes and be able to spit out ones where I either have all the ingredients or am only missing a couple (i.e., I could make a quick run to the store).
So I wrote something that takes a csv file with two columns, recipe name and a file name for the recipe. I have a text file with ingredients. I successfully created a list of ingredients, and I successfully opened and read in the file. I used regular expressions to search the file to see if my ingredients appear in the file. And that worked.
However, what I want to do is separate ingredients from the directions and I need to compare what I have on hand to what’s in the recipe. I could use regular expressions to search for “Directions” and lop off everything before that, split it and save it in a list. I tried to put the ingredients in a column and the directions in another, but it kept splitting each ingredient and each word in the directions.
I think if I put the recipes in a database with recipe name, recipe ingredients (as just a list), and directions, I could get close to what I’m thinking about. If the ingredients could be listed like [“1 tbps butter”, “2 tsp sugar”], then I could search each item, so I have sugar in my list which doesn’t appear as “sugar” in the recipe, but is in the string “2 tsp sugar”. I’ll give that a try tomorrow.