-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
235 lines (226 loc) · 10.7 KB
/
functions.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
item_types = []
current_sandwich = ''
# Checks JS outputs from server.py and returns outputs for JS.
class Output_Check():
def __init__(self, javascript_output, javascript_output_type):
global cart
self.chicken_typecases = ['c', 'chicken']
self.beef_typecases = ['b', 'beef']
self.tofu_typecases = ['t', 'tofu']
self.small_typecases = ['s', 'small']
self.medium_typecases = ['m', 'medium']
self.large_typecases = ['l', 'large']
if javascript_output_type == 'Sandwich Selection' or javascript_output_type == 'Drink Size Selection':
self.js_output = str(javascript_output).lower().strip()
else:
self.js_output = javascript_output
self.js_output_type = javascript_output_type
cart = Cart()
def check(self):
global current_sandwich
global current_drink_size
global current_fries_size
# Depending on type, have to change what's returned
if self.js_output_type == 'Sandwich Agreement':
self.python_output = 'What type of sandwich would you like?'
self.python_output_type = 'Sandwich Selection'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Sandwich Selection':
if self.js_output in self.chicken_typecases:
self.current_sandwich = 'chicken'
if self.js_output in self.beef_typecases:
self.current_sandwich = 'beef'
if self.js_output in self.tofu_typecases:
self.current_sandwich = 'tofu'
self.python_output = f'How many {self.current_sandwich} sandwiches would you like?'
current_sandwich = self.current_sandwich
self.python_output_type = 'Sandwich Amount'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Sandwich Amount':
self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility = cart.add('Regular', 'Sandwich', current_sandwich, self.js_output)
self.python_output = quantity_fixer(self.item_quantity, current_sandwich.lower(), 'regular', str(self.cart_types[0]).lower())
self.python_output_type = 'Sandwich Cart Addition'
return self.python_output, self.python_output_type, self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility
elif self.js_output_type == 'Sandwich Cart Addition':
self.python_output = 'Would you like a fountain drink?'
self.python_output_type = 'Drink Agreement'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Drink Agreement':
self.python_output = 'What size of drink would you like?'
self.python_output_type = 'Drink Size Selection'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Drink Size Selection':
if self.js_output in self.small_typecases:
self.drink_size = 'Small'
if self.js_output in self.medium_typecases:
self.drink_size = 'Medium'
if self.js_output in self.large_typecases:
self.drink_size = 'Large'
current_drink_size = self.drink_size
self.python_output = 'How many fountain drinks would you like?'
self.python_output_type = 'Drink Amount'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Drink Amount':
self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility = cart.add(current_drink_size, 'Drink', 'Fountain', self.js_output)
self.python_output = quantity_fixer(self.item_quantity, 'fountain', str(current_drink_size).lower(), 'drink')
self.python_output_type = 'Drink Cart Addition'
return self.python_output, self.python_output_type, self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility
elif self.js_output_type == 'Drink Cart Addition':
self.python_output = 'Would you like some fries?'
self.python_output_type = 'Fries Agreement'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Fries Agreement':
self.python_output = 'What size of fries would you like?'
self.python_output_type = 'Fries Size Selection'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Fries Size Selection':
if self.js_output in self.small_typecases:
self.fries_size = 'Small'
self.python_output_type = 'Fries Upgrade'
self.python_output = 'Would you like to mega-size your fries?'
if self.js_output in self.medium_typecases:
self.fries_size = 'Medium'
self.python_output_type = 'Fries Amount'
self.python_output = 'How many french fries would you like?'
if self.js_output in self.large_typecases:
self.fries_size = 'Large'
self.python_output_type = 'Fries Amount'
self.python_output = 'How many french fries would you like?'
current_fries_size = self.fries_size
return self.python_output, self.python_output_type
elif self.js_output_type == 'Fries Upgrade':
if self.js_output == 'y' or self.js_output == 'yes':
current_fries_size = 'Large'
self.python_output = 'How many french fries would you like?'
self.python_output_type = 'Fries Amount'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Fries Amount':
self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility = cart.add(current_fries_size, 'Fries', 'French', self.js_output)
self.python_output = quantity_fixer(self.item_quantity, 'french', str(current_fries_size).lower(), 'fries')
self.python_output_type = 'Fries Cart Addition'
return self.python_output, self.python_output_type, self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility
elif self.js_output_type == 'Fries Cart Addition':
self.python_output = 'Would you like some ketchup packets?'
self.python_output_type = 'Ketchup Agreement'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Ketchup Agreement':
self.python_output = 'How many ketchup packets would you like?'
self.python_output_type = 'Ketchup Amount'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Ketchup Amount':
self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility = cart.add('Regular', 'Packet', 'Ketchup', self.js_output)
self.python_output = quantity_fixer(self.item_quantity, 'ketchup', 'regular', 'packet')
self.python_output_type = 'Ketchup Cart Addition'
return self.python_output, self.python_output_type, self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligibility
elif self.js_output_type == 'Ketchup Cart Addition':
self.python_output = 'Your order is below! Thank you for shopping with us!'
self.python_output_type = 'Done!'
return self.python_output, self.python_output_type
elif self.js_output_type == 'Done!':
self.python_output = 'Your order is below! Thank you for shopping with us!'
self.python_output_type = 'Done!'
return self.python_output, self.python_output_type
def quantity_fixer(quantity, item, size, type):
if int(quantity) <=1:
if type == 'sandwich':
return f'Okay! Added a {size} {item} {type} to the cart!'
elif type == 'drink':
return f'Okay! Added a {size} {item} {type} to the cart!'
elif type == 'fries':
return f'Okay! Added {size} {item} {type} to the cart!'
elif type == 'packet':
return f'Okay! Added a {size} {item} {type} to the cart!'
else:
if type == 'sandwich':
return f'Okay! Added {quantity} {size} {item} {type}es to the cart!'
elif type == 'drink':
return f'Okay! Added {quantity} {size} {item} {type}s to the cart!'
elif type == 'fries':
return f'Okay! Added {quantity} {size} {item} {type} to the cart!'
elif type == 'packet':
return f'Okay! Added {quantity} {size} {item} {type}s to the cart!'
def clear_item_types():
global item_types
global current_sandwich
item_types = []
current_sandwich = ''
# Stores and sends variables for the cart.
class Cart():
def __init__(self):
self.item_id = 0
self.cart_total = 0
self.cart_prices = []
self.cart_sizes = []
self.cart_types = []
self.cart_names = []
self.has_sandwich = None
self.has_drink = None
self.has_fries = None
self.coupon_eligible = False
self.sandwich_prices = [5.25, 6.25, 5.75] # Chicken, Beef, and Tofu
self.drink_prices = [1.00, 1.75, 2.25] # Small, Medium, and Large
self.fries_prices = [1.00, 1.50, 2.00] # Small, Medium, and Large
self.ketchup_price = 0.25
def add(self, item_size, item_type, item_name, item_quantity):
global current_sandwich
global item_types
self.item_size = item_size
self.item_type = item_type
self.item_name = item_name
self.item_quantity = item_quantity
if self.item_type == 'Sandwich':
if self.item_name == 'chicken':
self.item_id = 0
if self.item_name == 'beef':
self.item_id = 1
if self.item_name == 'tofu':
self.item_id = 2
self.item_price = self.sandwich_prices[self.item_id]
if self.item_type == 'Drink':
if self.item_size == 'Small':
self.item_id = 0
if self.item_size == 'Medium':
self.item_id = 1
if self.item_size == 'Large':
self.item_id = 2
self.item_price = self.drink_prices[self.item_id]
print(self.item_price)
if self.item_type == 'Fries':
if self.item_size == 'Small':
self.item_id = 0
if self.item_size == 'Medium':
self.item_id = 1
if self.item_size == 'Large':
self.item_id = 2
self.item_price = self.fries_prices[self.item_id]
print(self.item_price)
if self.item_name == 'Ketchup':
self.item_price = self.ketchup_price
if int(self.item_quantity) >= 2:
for i in range(int(self.item_quantity)):
self.cart_sizes.append(self.item_size)
self.cart_types.append(self.item_type)
self.cart_names.append(self.item_name)
self.cart_prices.append(self.item_price)
else:
self.cart_sizes.append(self.item_size)
self.cart_types.append(self.item_type)
self.cart_names.append(self.item_name)
self.cart_prices.append(self.item_price)
item_types.append(self.cart_types[0])
print(item_types)
for item in item_types:
if item == 'Sandwich':
self.has_sandwich = True
if item == 'Drink':
self.has_drink = True
if item == 'Fries':
self.has_fries = True
if self.has_sandwich == True:
if self.has_drink == True:
if self.has_fries == True:
self.coupon_eligible = True
print(self.has_sandwich, self.has_drink, self.has_fries, self.coupon_eligible)
self.cart_total = sum(self.cart_prices)
self.cart_total = '{:.2f}'.format(self.cart_total)
return self.cart_sizes, self.cart_types, self.cart_names, self.cart_prices, self.cart_total, self.item_quantity, self.coupon_eligible