Hello!
I recently came across EDAMAM and found out that it offers a free API for developers (not unlimited though) for nutritional analysis! After signing up, you create an app, and get an app id and app key. By using those along with the endpoint, it is possible to find out the nutritional analysis of what you eat. Yes, there are plenty of apps outside allowing you to do that, so this is just one of the options:)
APP_ID = ' ' APP_KEY = ' ' api_endpoint = 'https://api.edamam.com/api/nutrition-details' url = api_endpoint + '?app_id=' + APP_ID + '&app_key=' + APP_KEY headers = {'Content-Type' : 'application/json'}
For example, let us try an almond milk recipe (which I just made up):
recipe = {'title': 'Almond Milk', 'ingr': ['50g raw almonds', '100ml water', '3g sea salt']} r = requests.post(url, headers = headers, json = recipe)
To see all the keys in the resulting json:
almondmilk_info.keys()
The output:
dict_keys(['uri', 'yield', 'calories', 'totalWeight', 'dietLabels', 'healthLabels', 'cautions', 'totalNutrients', 'totalDaily', 'totalNutrientsKCal'])
We see that one of the keys is totalNutrients which I find interesting. Now, I will put that into a data frame and transpose it to make it more readable.
almondmilk_nutr = pd.DataFrame(almondmilk_info['totalNutrients']).transpose() almondmilk_nutr
Here is how the output looks like:
We can also check the healthLabels key:
almondmilk_nutr_health = pd.DataFrame(almondmilk_info['healthLabels']) almondmilk_nutr_health.columns = ['health_labels'] almondmilk_nutr_health
The resulting data frame:
Have fun!
Note: I have no affiliation with this website, I just use their free API very happily