Week 1 – Choosing meals
A bunch of the solutions I brainstormed revolved around querying a database, although I also liked the thought of paring down the options based on the user’s preferences. So that’s what we’ve ended up with: take a huge database, pare it down based on my preferences, then return a random selection of the remaining recipes.
The best part about this process was finding an amazing recipe database: https://github.com/fictivekin/openrecipes. These guys did exactly what I would have done, which is to scrape existing cooking websites to acquire the key details about their recipes. That said, creating a web scraper would have been a huge challenge, so I’m glad that I could stand on the shoulders of giants! (Note to self: put ‘build a web scraper’ on list of potential projects.)
The code is on Github here: https://github.com/dtsmash/recipe-selector. If you want to run it yourself, you’ll also need to download the recipe database from the link above – the file is too large to include in the project folder.
In a nutshell, the program:
- Reads the database (stored as a json file) into Python as an array of dictionaries – each recipe is a dictionary with attributes like ‘name’, ‘ingredients’, etc.
- Asks the user their preferences (currently I’m asking about maximum preparation time and required ingredients, but lots more could be added – see below)
- Pares the total database down to only the recipes that match the user’s preferences
- Selects a number (default five) of recipes and provides the user with their names
- Opens the URL of the recipe the user selects
Pretty basic, but works quite nicely. Some improvements I’d like to make in the future:
- The program’s ability to understand what ingredient is wanted is limited. I’ve fixed case sensitivity and built in a check for whether the ingredient even exists in the database, but it still doesn’t understand that, for example, potatoes ≠ sweet potatoes, or that potatoes = potato. The latter issue would be fairly easy to fix, come to think of it, by prompting the user to supply the ingredient as a singular noun (will work for most English nouns, at least).
- A nicer UI than just typing in the Terminal window would be pretty nice, and improve usability.
- More ways to thin down the recipe list, e.g. ingredients to avoid
- Creation of a shopping list after recipe selection (someone from the NY Times did something similar and theirs has a shopping list creator at the end, jealous)
I want to use this blog to also be reflective about the problem solving process each week – deliberate learning and all that.
So this week, what did I learn?
- Although I also like Ruby from what I’ve seen so far (I’m picking it up as part of a front-end dev learning track), I still have a much better grasp of Python.
- Moreover, my main (huge) advantage in Python is that I know how to search for knowledge I lack. Inevitably, and especially for a simple project like this, the fix for whatever difficulty I’m having has been outlined beautifully in some Stack Exchange thread. But to get there, I need to know enough of the lingo and the fundamentals of the language to formulate my question well. That’s a fairly useful realisation for my future programming language learning: first priority, learn enough to be able to find the answers yourself.
- Good gracious is it nice to be able to stand on the shoulders of giants. My end of the solution was pretty simple, but entirely prefaced on the existence of a good database.
- Àpropos, I am now ever more of a proponent of open, accessible data. The world would be enriched to an unbelievable extent by data being made more freely and easily available. Governments of the world, I’m looking at you – democratic accountability and transparency requires this!
- I super love problem solving and coding – that was a fun task!