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
Wdef RandomRecipe():
import requests
import json
#imports the function used to work with apis
api= "cbd2e8ce18e04227b99205001c304bfa"
#varaible to keep track of the api key
r = requests.get("https://api.spoonacular.com/recipes/random?number=1&apiKey=cbd2e8ce18e04227b99205001c304bfa&limitLicense=true")
#retrieves the recipe library from the api
r_json= r.json()
#gets library in reccipe format
for n in r_json['recipes']:
#creates variables for the title and the summary
title=(n['title'])
summary=(n['summary'])
print("The random recipe I've got for you was " + title)
#outputs to the user telling them what recipe they have
string=summary.replace("<b>", "")
string2=string.replace("</b>", "")
string3=string2.replace("</a>", "")
string4=string3.replace("<a>", "")
string5=string4.replace("<a", "")
string6=string5.replace(">", "")
print(string6)
#removes all the symbols that we don't want from the library so that the user jus tsees standard english
print("")
state= 0
while state == 0:
happy=input("Are you happy with the recipe you have recieved?")
#checks the user if they're happy with this recipe
happy2= happy.lower()
if happy2 == "yes" or happy2 == "y" or happy2 == "yep" or happy2 == "yeah" or happy2 == "happy":
print("The ingredients you'll need are:")
for i in r_json['recipes'][0]['extendedIngredients']:
#prints out the ingredients and measures from the api library
print(i['originalString'])
print("")
for m in r_json['recipes'][0]['analyzedInstructions'][0]['steps']:
print("This is step number " + str(m['number']))
print("")
print(m['step'])
print("")
#then links back to mainprogram
break
if happy2 == "no" or happy2 == "n" or happy2 == "nah" or happy2 == "not happy" or happy2 == "nope":
state2= 0
while state2 == 0:
ask=input("Would you like to recieve another recipe?")
ask2= ask.lower()
if ask2 == "yes" or ask2 == "yeah" or ask2 == "yep" or ask2 == "y" or ask2 == "another recipe":
print("")
RandomRecipe()
#recursive function, links back on itself
if ask2 == "no" or ask2 == "nah" or ask2 == "n" or ask2 == "nope":
print("Im sorry I couldn't help you today")
#would link back to the mainprogram at this point in time
state=1
state2=1
break
else:
#lets the user know that their answer isnt registered
print("Your answer is unrecognised")
state2= 0
RandomRecipe()