I’m pretty new to Python. I’m trying to build a multiple choice quiz using Edamam API. It’s currently not flagging any errors but there has to be a neater way to ask the questions, I’m just stuck as some of them require pulling through data from Edamam.
import requests
def recipe_search(meal_type, ingredient, Health):
app_id = "..."
app_key = "..."
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():
meal_type = input("Are you looking for a particular type of meal?: ")
if meal_type == "yes":
input("Select an option from the following list:\n - breakfast\n - brunch\n - lunch\n - snack\n - teatime\n > ")
else: pass
Health = input("Do you have a dietary requirement?: ")
if Health == "yes":
input("Select an option from the following list:\n - vegan\n - vegetarian\n - paleo\n - dairy-free\n - gluten-free\n"
" - wheat-free\n - fat-free\n - low-sugar\n - egg-free\n - peanut-free\n - tree-nut-free\n - soy-free\n"
" - fish-free\n - shellfish-free\n >")
else: pass
ingredient = input("What ingredient would you like to use?:\n > ")
results = recipe_search(meal_type, ingredient, Health)
for result in results:
recipe = result["recipe"]
print(recipe["ingredientLines"])
print(recipe["label"])
print(recipe["calories"])
print(recipe["dishType"])
print(recipe["cuisineType"])
print()
run()
new_item = input("Add recipe to meal planner?:\n > ")
with open("recipe.txt", "r") as recipe_file:
recipes = recipe_file.read()
recipes = recipes + new_item + "\n"
with open("recipe.txt", "w+") as recipe_file:
recipe_file.write(recipes)