-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbank.py
38 lines (30 loc) · 1.18 KB
/
bank.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
import json
import aioconsole
class Bank:
show = True
local = True
centralHostName = 'localhost' if local else '192.168.2.1'
centralPortNr = 6666
centralBankCode = 'noob'
def __init__ (self, bankCode):
self.bankCode = bankCode
def print (self, *args, end = '\n', show = True):
if self.show and show:
print (f'{self.bankCode.upper ()} -', *args, end = end, flush = True)
async def input (self, *args):
if args:
self.print (*args, end = '')
return (await aioconsole.ainput ('')) .lower ()
async def send (self, socket, role, message, show = True):
self.print (f'Sent {role}: {message}', show = show)
return await socket.send (json.dumps (message))
async def recv (self, socket, role, show = True):
message = json.loads (await socket.recv ())
self.print (f'Received {role}: {message}', show = show)
return message
def match (self, commandStart, *commandSet):
for command in commandSet:
if command.startswith (commandStart):
return True
else:
return False