I am looking to search for recipes using Edamam’s API using two criteria: ingredient and dietary requirement. This is my code but it doesn’t seem to work as it only seems to give me results based on ingredients. How can I fix it?
import requests
def recipe_search(ingredient):
# Register to get an APP ID and key https://developer.edamam.com/
app_id = '7ddad259'
app_key = '7224bfa2898e8a64713bc90468172e24'
result = requests.get(
'https://api.edamam.com/search?q={}&app_id={}&app_key={}'.format(ingredient, app_id, app_key)
)
data = result.json()
return data['hits']
def run():
ingredient = input('Enter an ingredient: ')
healthLabels = input('Enter a dietary requirement: ')
results = recipe_search(ingredient)
for result in results:
recipe = result['recipe']
healthLabels = recipe['healthLabels']
if healthLabels == healthLabels:
print(recipe['label'])
print(recipe['url'])
else:
print("No Result")
run()
New contributor
EMJH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.