diff --git a/recipe_bot/food.py b/recipe_bot/food.py new file mode 100644 index 0000000000..15509595b8 --- /dev/null +++ b/recipe_bot/food.py @@ -0,0 +1,55 @@ +import random + +# some common food predefined instruction +recipe_database = { + "spaghetti bolognese": { + "ingredients": ["spaghetti", "ground beef", "tomato sauce", "onion", "garlic", "olive oil"], + "instructions": [ + "Cook spaghetti according to package instructions.", + "In a large skillet, heat olive oil over medium heat.", + "Add chopped onion and minced garlic to the skillet. Cook until softened.", + "Add ground beef and cook until browned.", + "Stir in tomato sauce and simmer for 10 minutes.", + "Serve the bolognese sauce over cooked spaghetti." + ] + }, + "chicken stir-fry": { + "ingredients": ["chicken breast", "soy sauce", "ginger", "garlic", "vegetables", "vegetable oil"], + "instructions": [ + "Cut chicken breast into small pieces.", + "In a wok or skillet, heat vegetable oil over high heat.", + "Add minced ginger and garlic. Stir-fry for a minute.", + "Add chicken and cook until no longer pink.", + "Add vegetables and cook until tender-crisp.", + "Pour soy sauce over the mixture and stir-fry for an additional minute.", + "Serve the chicken stir-fry with rice or noodles." + ] + }, + # to Add more recipes here +} +# this function generates a formatted content containing the ingredients and instructions for the recipe. +def get_recipe(dish_name): + recipe = recipe_database.get(dish_name.lower()) + if recipe: + return recipe + else: + return None + +def generate_recipe_response(recipe): + if recipe: + response = f"Here's the recipe for {recipe}: \n\n" + response += "Ingredients:\n" + for ingredient in recipe["ingredients"]: + response += "- " + ingredient + "\n" + response += "\nInstructions:\n" + for step, instruction in enumerate(recipe["instructions"], start=1): + response += str(step) + ". " + instruction + "\n" + return response + else: + return "Sorry, We don't have the recipe for that dish\nPlease!look for another one." + + +dish = input("Enter the name of a dish: ") +recipe = get_recipe(dish) +response = generate_recipe_response(recipe) +print(response) diff --git a/recipe_bot/recipe_bot.py b/recipe_bot/recipe_bot.py new file mode 100644 index 0000000000..4cac2639c6 --- /dev/null +++ b/recipe_bot/recipe_bot.py @@ -0,0 +1,34 @@ +import requests + +def get_recipe(dish): + api_key = "3433d479b6b54fcd90552b35da3f3a63" + endpoint = f"https://api.spoonacular.com/recipes/716429/information?includeNutrition=false" + + response = requests.get(endpoint) + data = response.json() + + + if "results" in data and len(data["results"]) > 0: + recipe = data["results"][0] # Get the first recipe + return recipe + else: + return None + +def generate_recipe_response(recipe): + if recipe: + response = f"Here's the recipe for {recipe['title']}: \n\n" + response += "Ingredients:\n" + for ingredient in recipe['ingredients']: + response += "- " + ingredient + "\n" + response += "\nInstructions:\n" + response += recipe['instructions'] + return response + else: + return "Sorry, I couldn't find a recipe for that dish." + +dish = input("Enter the name of a dish: ") +recipe = get_recipe(dish) +response = generate_recipe_response(recipe) +print(response) + +