-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe.py
64 lines (50 loc) · 1.67 KB
/
recipe.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import json, os
from dotenv import load_doten
class RecipeClient:
def __init__(self, api_key):
self.endpoint = 'https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/'
self.api_key = api_key
def find_by_ingredients(self, ingredients):
url = self.endpoint + 'recipes/findByIngredients'
params = {
'fillIngredients': False,
'ingredients': ingredients,
'limitLicense': False,
'number': 5,
'ranking': 1
}
headers = {
'X-Mashape-Key': self.api_key,
'Accept': 'application/json'
}
return requests.get(url, params=params, headers=headers).json()
def find_by_cuisine(self, cuisine):
url = self.endpoint + 'recipes/search'
payload = {
'number': 5,
'query': '',
'cuisine': cuisine
}
headers = {
'X-Mashape-Key': self.api_key
}
return requests.get(url, params=payload, headers=headers).json()['results']
def get_info_by_id(self, id):
url = self.endpoint + 'recipes/' + str(id) + '/information'
params = {
'includeNutrition': False
}
headers = {
'X-Mashape-Key': self.api_key
}
return requests.get(url, params=params, headers=headers).json()
def get_steps_by_id(self, id):
url = self.endpoint + 'recipes/' + str(id) + '/analyzedInstructions'
params = {
'stepBreakdown': True
}
headers = {
'X-Mashape-Key': self.api_key
}
return requests.get(url, params=params, headers=headers).json()