-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
38 lines (32 loc) · 1.18 KB
/
commands.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
from confectionary.stockroom import add_material, check_raw_materials, allocate_raw_materials
from confectionary.store import define_sweets, update_cash_desk
from confectionary.workshop import define_sweets_spec
from bank.bank_server import send_report_to_bank
def add(command):
try:
action, material, quantity = command.split()
except ValueError:
return False
return add_material(material, quantity)
def define(command):
try:
command, materials = command.split(': ')
*action, sweets_name, price = command.split()
if action != ["define", "sweets"]:
return False
req1 = define_sweets(sweets_name, price)
req2 = define_sweets_spec(sweets_name, materials)
except ValueError:
return False
return req1 and req2
def buy(command):
*action, sweets_name, quantity = command.split()
if action != ["customer", "buy"]:
raise ValueError
quantity = int(quantity)
if check_raw_materials(sweets_name, quantity):
report = update_cash_desk(sweets_name, quantity)
allocate_raw_materials(sweets_name, quantity)
send_report_to_bank(report)
return True
return False