Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import random as rand
import spoonacular as sp
import Find_allergens as fa
api = sp.API("18b4d68fbd11492f8ac5fd4c771d2b44")
def randomRecipe():
title = []
ingredientsList = []
instructions = []
randNum = rand.randint(0, 800000)
response = api.get_recipe_information(id=randNum)
data = response.json()
title.append(data['title'])
for i in range(0, len(data['extendedIngredients'])):
ingredientsList.append(data['extendedIngredients'][i]['name'])
instructions.append(data['instructions'])
title = str(title).replace('[','').replace(']','').replace("'","")
ingredientsList = str(ingredientsList).replace('[','').replace(']','').replace("'","")
instructions = str(instructions).replace('[','').replace(']','').replace("'","")
return title, ingredientsList, instructions
def idRecipe(idSelect):
title = []
ingredientsList = []
instructions = []
response = api.get_recipe_information(id=idSelect)
data = response.json()
title.append(data['title'])
for i in range(0, len(data['extendedIngredients'])):
ingredientsList.append(data['extendedIngredients'][i]['name'])
instructions.append(data['instructions'])
title = str(title).replace('[','').replace(']','').replace("'","")
ingredientsList = str(ingredientsList).replace('[','').replace(']','').replace("'","")
instructions = str(instructions).replace('[','').replace(']','').replace("'","")
return title, ingredientsList, instructions
def chosenRecipe(userInput):
recipe = []
response = api.parse_ingredients(userInput, servings=2)
data = response.json()
queryData = data[0]['name']
response = api.search_recipes_complex(query=queryData, number=1)
data = response.json()
try:
idSelect = data['results'][0]['id']
recipe = idRecipe(idSelect)
except:
recipe = []
return recipe