Spoonacular API is food and recipes API, allowing you to scrape web data from an online database with hundreds of thousands of recipes, products and ingredients. Using Python, I wrote a script that takes user input (what ingredients do you have? What are your dietary requirements?), sends a request to the API, and then returns a tailored list of recipes. The list also provides the user with calorie information about the different dishes. There are many other endpoints too, including the option to receive a random food joke, wine recommendations and recipes based on your carbohydrate limits.
Choosing a recipe
In my script, I ask users: what’s in your store cupboard? You can add ingredients like egg or tomato, and separate each one with a comma.
In this example, I add “spinach, egg”, which I type into the Python console at the bottom of the screen. I ask the user for their dietary requirements.If the user types in “yes”, they receive a second question: “What is your dietary requirement?” If the user says no, or I don’t know, they receive a list based on their ingredients (the values of the above input). In this example, I stipulate a Vegetarian-friendly list of recipes. Each one is listed along with its calorie count per serving. After this, a question pops up, asking the user which recipe they like the look of. In this example, I choose “Baked Eggs with Spinach and Tomatoes”. The program then returns the list of ingredients I need. Finally, the user is asked if they would like to continue to the recipe steps for that recipe. And voilà! The program returns the recipe steps, along with the average number of servings it creates.
Carb counting
I also wrote a program which returns recipes based on Max and Min values for carbohydrate intake. It also writes the ingredients to an external file (you can see on the left), called “recipes_carb_limit_txt”. The results you get here in the python console look a little different to the ones above, because the response is in a dictionary format. A dictionary is a comma-separated list of key/value pairs inside curly brackets: {}.
Random Food Joke
This simple program returns a random (usually punny) joke.