· 6 years ago · Jan 08, 2020, 07:40 AM
1import requests
2
3
4def build_recipe_query(api_key, cuisine):
5 url = 'https://api.spoonacular.com/recipes/search?cuisine=' + cuisine + \
6 "&apiKey=" + api_key + "&addRecipeInformation=True"
7 r = requests.get(url)
8
9 if r.status_code == 401:
10 print("invalid recipe api key")
11 raise Exception
12 return r.json()
13
14
15if __name__ == "__main__":
16 api_key = "772cdeb0dcb4477b91253c44a3395b87"
17 response = build_recipe_query(api_key, "italian")
18 recipes = response["results"]
19 ingredients = []
20 for recipe in recipes:
21 print(recipe)