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
def FoodPrices():
import requests
import json
#imports the libraries needed for this code to work
url="https://api.spoonacular.com/recipes/complexSearch?apiKey=cbd2e8ce18e04227b99205001c304bfa&sort=price&addRecipeInformation=true"
#the basic url for the api
number=input("How many recipes would you like to recieve? ")
userprice=input("Would you like cheap recipes or expensive ones? ")
#asks the user their preference
if userprice == "cheap":
price= "asc"
if userprice == "expensive":
price= "desc"
#retireves the variables for the specific user request
newurl= url + "&sortDirection=" + price + "&number=" + number
#puts together the specific user url
r=requests.get(newurl)
#retrieves the url into python
r_json=r.json()
#puts the api into dictionary format so that it can be read and picked apart
titlelist=[]
for n in r_json['results']:
#searches through the 'results' part of the library
titlelist.append(n['title'])
#adds the key's result into a list
print(n['title'])
#prints the keys result out to the user
q= n['servings']
y= n['pricePerServing']
cost= q*y
#finds out the cost of the product
print("The cost is $" + str(cost))
#outputs this cost to the user of the product
print("")
rsp=input("Would you like any of these recipes? ")
#asks the user if they are interested in any of these recipes
if rsp == "yes":
x=0
recipe=input("Please enter the recipe of your choice ")
state=0
while state == 0:
if titlelist[x] == recipe:
print("You have chosen " + recipe)
for m in r_json['results'][x]['analyzedInstructions'][0]['steps']:
#cycles through the dictionary to find the steps part of the library
for l in m['ingredients']:
print("You must get " + str(l['name']) + " for this step")
#out puts the name of the ingredient that they need to have for the specific step
print("")
print("This is step number " + str(m['number']))
#tells the user what step number theyre on
print("")
print(m['step'])
#outputs the specific instruction for that step
print("")
break
#ends the loop and goes to main program
if x == len(titlelist)-1:
print("You have entered the recipe in wrong")
#notifies the user that they have entered the recipe in wrong
state= 1
else:
x=x+1
state=0
#continues the loop
if rsp == "no":
ask=input("Would you like to try again and increase the number size?")
if ask == "yes":
FoodPrices()
#recursive function- starts again
if ask == "no":
print("Im sorry that I couldn't help you today")
#ends the function, would loop back to mainprogram
FoodPrices()