-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewRecipes.py
103 lines (91 loc) · 3.41 KB
/
viewRecipes.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
101
102
103
# from dbConnection import Lookup
import os
import json
class ViewRecipes():
"""description of class"""
def viewAll(self):
recipeHolder = {}
for file in os.listdir():
if file.endswith(".json"):
with open(file, "r") as jsonRecipe:
f = json.load(jsonRecipe)
if len(recipeHolder) == 0:
recipeHolder = f.copy()
else:
recipeHolder.update(f)
jsonRecipe.close()
for reName, reInfo in recipeHolder.items():
print("\nRecipe Name:", reName)
for key in reInfo:
print(key + ':', reInfo[key])
def viewSelect(self):
typeInput = 0
recipeType = ''
recipeHolder = {}
while typeInput <= 0 or typeInput > 7:
try:
typeInput = int(input(
'What type of recipe are you looking for?\n(1) for Breakfast \n(2) for Main Dish \n'
'(3) for Side Dish \n(4) for Soup \n(5) for Bread \n(6) for Dessert \n(7) for Drink \n'))
except:
typeInput = 0
if typeInput == 1:
recipeType = 'Breakfast.json'
elif typeInput == 2:
recipeType = 'Main_Dish.json'
elif typeInput == 3:
recipeType = 'Side_Dish.json'
elif typeInput == 4:
recipeType = 'Soup.json'
elif typeInput == 5:
recipeType = 'Bread.json'
elif typeInput == 6:
recipeType = 'Dessert.json'
elif typeInput == 7:
recipeType = 'Drink.json'
else:
print('Incorrect input')
for file in os.listdir():
if file == recipeType:
with open(file, "r") as jsonRecipe:
f = json.load(jsonRecipe)
recipeHolder = f.copy()
jsonRecipe.close()
if len(recipeHolder) == 0:
print("There are currently no recipes for this type.")
for reName, reInfo in recipeHolder.items():
print("\nRecipe Name:", reName)
for key in reInfo:
print(key + ':', reInfo[key])
def printLoop(self, tupHold):
for tup in tupHold:
for st, var in enumerate(tup):
if st == 0:
print('Name: %s' % (var))
elif st == 1:
if var == None or var == '':
pass
else:
print('Type: %s' % (var))
elif st == 2:
print('Ingredients: %s' % (var))
elif st == 3:
if var == None or var == '':
pass
else:
print('Bake Time: %s' % (var))
elif st == 4:
if var == None or var == '':
pass
else:
print('Bake Temp: %i' % (var))
elif st == 5:
print('Directions: %s' % (var))
elif st == len(tup) - 1:
if var == 0:
print('Favorite: No')
else:
print('Favorite: Yes')
print()
else:
print('ERROR')