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 sys
import spoonacular #api imported
#our own files from the repository are imported here
from ingrediantFunction import getRecipeByIngredients
from LDgreetingFunction import greeting_Function
from allergyFuction import allergen_reviewer#we need an allergy function
import toby
#checks to see what the user is inputting and then uses the imported functions to respond to the user.
#The below code was adapted from charle44/Chatbot link:https://github.coventry.ac.uk/charle44/ChatBot/blob/master/main.py
#Most of the code has been changed, so only the choices part from the user Input is similar.
while out = True: #created a while loop around the whole code
greeting_Function() #added in our greeting function
userInput = input("What do you want to look at today? 1) Random recipes 2) Free from recipes 3) Specfic Cuisines 4) Search by Ingredient 5) Food Joke 6) Exit ")
#inputs have been changed to suit our chatbot
moreInfo = False #added a check to see whether user wanted a specific type of recipe.
if userInput == 1 or userInput.lower() == 'random':
ranRecipe = True #gives user a random recipe
allergyInfo = input("Are there any allergies we need to know? (Yes/No) ")
while moreInfo == False:
if allergyInfo.lower == 'yes': #added an if statement to check for extra requirements
moreInfo = True
allergen_reviewer() #allergy function we have created and added in
elif allergyInfo == 'no':
continue
else:
print("Sorry I didn't understand what you asked me to do, please enter again.")
moreInfo = False
recipe =[] #changed the output of the code to something that we have written ourselves
recipe = toby.randomRecipe(rand.randint(0, 800000))
print("Title: " + str(recipe[0]))
print("Ingredient List: " + str(recipe[1]))
print("Instructions: " + str(recipe[2]))
out = True
elif userInput == 2 or userInput.lower() == 'free':
allergyFunction = True
allergyInfo = input("Would you like a specific cuisine? (Please type name of cuisine, eg. Indian) ")
while moreInfo == False:
if allergyInfo.lower() == 'indian' or allergyInfo.lower() == 'japanese' or allergyInfo.lower() == 'chinese' or allergyInfo.lower()== 'greek':
moreInfo = True
find_keywords(userInput) #parsing function we have created and added in
allergen_reviewer() #allergy function we have created and added in
break
elif allergyInfo.lower() == 'no':
continue
else:
print("Sorry I didn't understand what you asked me to do, please enter again.")
moreInfo = False
recipe =[] #changed the output of the code to something that we have written ourselves
recipe = toby.chosenRecipe(userInput)
print("Title: " + str(recipe[0]))
print("Ingredient List: " + str(recipe[1]))
print("Instructions: " + str(recipe[2]))
out = True
#code to ask user if they want a specific cuisine for their recipe
elif userInput == 3 or userInput == ['indian', 'japanese', 'chinese', 'cuisine', 'greek']:
cuisineFunction = True
allergyInfo = input("Are there any allergies we need to know? (Yes/No) ")
while moreInfo == False:
if allergyInfo.lower() == 'yes':
moreInfo = True
allergen_reviewer() #allergy function we have created and added in
elif allergyInfo.lower() == 'no':
continue
else:
print("Sorry I didn't understand what you asked me to do, please enter again.")
moreInfo = False
recipe =[] #changed the output of the code to something that we have written ourselves
recipe = toby.chosenRecipe(userInput)
print("Title: " + str(recipe[0]))
print("Ingredient List: " + str(recipe[1]))
print("Instructions: " + str(recipe[2]))
out = True
#checks to see if user is searching for recipes by searching for an ingredient.
elif userInput == 4 or userInput == 'ingredient':
ingredient = input("What ingredient are you looking for? ")
getRecipeByIngredients(ingredient) #function imported from another file
if getRecipeByIngredients == True:
ingredient = input("What ingredient are you looking for? ")
else:
print("I did not understand what you have entered.")
out = True
#responds with a joke for the user
elif userInput == 5 or userInput.lower() == 'joke':
response = api.get_a_random_food_joke() #function from the spoonacular api
data = response.json()
print(data['text'])
out = True
#allows user to exit the chatbot
elif userInput == 6 or userInput.lower() == 'exit':
print("Thank you for using Eugene, have a nice day!")
sys.exit()
out = False
else:
print("I did not understand what you wanted me to do. Please try again!")
out = False
return out
#end of adaptation from charle44/Chatbot from Coventry GitHub