forked from czeng07/alexas-kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe.py
executable file
·28 lines (25 loc) · 947 Bytes
/
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
import json
from pprint import pprint
import unirest
import sys
def formatIngs(i):
"""Takes in a list of ingredients, formats them so that they can be used"""
with open(i) as data_file:
data = json.load(data_file)
ings = ""
j = data["ingredients"]
for x in j:
if int(x["quantity"]) > 0:
ings += "%2C" + str(x["name"]).lower()
return ings[3:]
def getRecipe(ings):
"""returns a json of the recipe"""
response = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?fillIngredients=true&ingredients=" + ings + "&limitLicense=false&number=10&ranking=2",
headers={
"X-Mashape-Key": "8v3t0cFZU7mshkZplOb0JmeeGgH6p1S5OL0jsns4c8bSUeFeB3",
"Accept": "application/json"
})
with open('options.json', 'w+') as outfile:
json.dump(response.body, outfile)
#ingredients = formatIngs(sys.argv[1])
#getRecipe(ingredients)