-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
100 lines (82 loc) · 2.53 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import database as db
menu = """Please Select One of the following Options:
1. Add Recipes
2. Add Ingredients
3. View all Recipes
4. View all Ingredients
5. Add Ingredient(s) to Recipe
6. View a Recipe & its Ingredients
7. Exit
your selection: """
welcome = """
---------------------------------
| WELCOME TO MY RECIPE APP |
---------------------------------
"""
print(welcome)
db.create_tables()
def add_recipe():
recipe_name = input("Enter recipe name: ")
db.add_recipe(recipe_name)
def add_ingredients():
ingredient_name = input("Enter ingredient name: ")
db.add_ingredient(ingredient_name)
def add_recipe_ing():
recipe_name = input("Recipe name: ")
ingredient_name = input("Ingredient name: ")
recipeName = db.find_recipe_ing_name(ingredient_name)
if recipe_name in str(recipeName):
print(str(recipeName))
print(f"\n<-- {recipe_name} already has {ingredient_name} -->\n")
else:
db.add_recipe_ing(recipe_name, ingredient_name)
print("\n<-- Data saved successfully -->\n")
def print_all_recipe(header, recipes):
print(f"<-- {header} Recipes -->")
_id = 1
for recipe, in recipes:
print(f"{_id}. {recipe}")
_id += 1
def print_all_ingredients(header, ingredients):
print(f"<-- {header} Ingredients -->")
_id = 1
for ingr, in ingredients:
print(f"{_id}. {ingr}")
_id += 1
def print_all_recipe_ing():
name = input("Recipe name: ")
ingredients = db.get_recipe_ing(name)
if ingredients:
print_all_ingredients(name, ingredients)
else:
print("No ingredients")
print("------------\n")
while (user_input := input(menu)) != "7":
if user_input == "1":
try:
add_recipe()
except Exception as e:
print(e, "::Error: recipe already exist.::")
elif user_input == "2":
try:
add_ingredients()
except Exception as e:
print(e, "::Error: ingredient already exist.::")
elif user_input == "3":
recipes = db.get_all_recipe()
if recipes:
print_all_recipe("All", recipes)
else:
print("No recipe found!")
print("------------\n")
elif user_input == "4":
ingr = db.get_all_ingredients()
if ingr:
print_all_ingredients("All", ingr)
else:
print("No ingredient found!")
print("------------\n")
elif user_input == "5":
add_recipe_ing()
elif user_input == "6":
print_all_recipe_ing()