-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpoonacularAPIHandler.py
More file actions
45 lines (36 loc) · 1.91 KB
/
SpoonacularAPIHandler.py
File metadata and controls
45 lines (36 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#This class handles all requests from SpoonacularAPI
#The API has a limit on how many times a key can call per day, so be careful
import requests
global spoonacular_key
class Spoonacular:
#Initialize the class, and set the api key
def __init__(self) -> None:
global spoonacular_key
spoonacular_key= "2badc30033bf439fa3f0946976d49a11"
print("Spoonacular initialized successfully.")
#Gets 5 recipes from Spoonacular based on the user's health and pantry fed to the query
@staticmethod
def generateRecipes(param):
url = "https://api.spoonacular.com/recipes/complexSearch"
#Limit to 5 for testing as to not deplete point limit
query = url + "?" + "apiKey=" + spoonacular_key + "&number=5" + param
response = requests.get(query)
return response.json()
#Gets the nutritional information of a recipe from Spoonacular based on the recipe ID
@staticmethod
def getNutrition(id):
url = f"https://api.spoonacular.com/recipes/{id}/information"
#Must make sure to only use recipes with instructions, there is no need for wine pairing or taste data right now
param = "&includeNutrition=true&addWinePairing=false&addTasteData=false"
query = url + "?" + "apiKey=" + spoonacular_key + param
response = requests.get(query)
return response.json()
#Gets the instructions on how to make a recipe
@staticmethod
def getInstructions(id):
url = f"https://api.spoonacular.com/recipes/{id}/information"
#We would have received Nutrition data already, there is no need for wine pairing or taste data right now
param = "&includeNutrition=false&addWinePairing=false&addTasteData=false"
query = url + "?" + "apiKey=" + spoonacular_key + param
response = requests.get(query)
return response.json()