had a few Python classes and tinkering with an old project. I'm using an API to help the user decide on a recipe to cook. One of the questions is if they have dietary/meal type requirements. The API documentation has parameters for the requirements but I don't know how to make it work if the user has no dietary/meal type requirements. I tried to do an if else statement but PyCharm got confused. This is my code:
import requests
def recipe_search(ingredient, mealtype, dietary):
# You need to register as a developer with Edamame to get an Application ID and Key
# These can be found in the applications section of the dashboard once you have signed in
app_id = "INSERT APP ID"
app_key = "INSERT APP KEY"
result = requests.get(
'https://api.edamam.com/search?q={}&app_id={}&app_key={}&mealType={}&health'.format(ingredient, app_id, app_key,
mealtype, dietary))
data = result.json()
return data["hits"]
def run():
ingredient = input("Enter an ingredient: ")
mealtype = input(
"What type of meal do you want? \n Choose from breakfast/lunch/dinner/snack/teatime/any. You can input multiple meals but they must be seperated with commas.")
dietary = input(
'Do you have any dietary requirements? \n Choose and enter from vegan/vegetarian/paleo/dairy-free/gluten-free/wheat-free/fat-free/low-sugar/egg-free/peanut-free/tree-nut-free/soy-free/fish-free/shellfish-free. \n You can enter multiple dietary requirements, but they must be seperated with commas.')
results = recipe_search(ingredient, mealtype, dietary)
for result in results:
recipe = result["recipe"]
print(recipe["label"])
print(recipe["uri"])
print()
run()
This is the API that I'm using: https://developer.edamam.com/edamam-docs-recipe-api