def insert_card(number): client = ses.connect_to("0.0.0.0", 1919) ses.send(number, client) return client # def
def get_cash(atm): mess = 'Introduce sum to get:\n' ses.send(mess, atm.atm) resp = ses.recv(atm.atm) update_balance(atm.client_card, -float(resp)) mess = 'Balance changed\n1. Back\n' ses.send(mess, atm.atm) get_back(atm) pass
def get_pin(atm): mess = 'Hi, please type PIN\n' ses.send(mess, atm.atm) for i in range(3): pin = ses.recv(atm.atm) acc = get_acc(atm.client_card, pin) if acc: atm.client_acc = acc break show_main(atm)
def show_main(atm): mess = 'Hi, what would you like to do?\n0. Eject card\n1. Change PIN\n2. Transfer money\n3. Get cash\n4. Check balance\n' ses.send(mess, atm.atm) resp = ses.recv(atm.atm) if resp == '0': eject_card(atm) elif resp == '1': change_pin(atm) elif resp == '2': tranfer_mony(atm) elif resp == '3': get_cash(atm) elif resp == '4': chek_balance(atm)
def change_pin(atm): mess = 'Please enter old PIN\n' ses.send(mess, atm.atm) resp = ses.recv(atm.atm) if resp == atm.client_acc['password']: mess = 'Please enter new PIN\n' ses.send(mess, atm.atm) resp = ses.recv(atm.atm) atm.client_acc['password'] = resp update_acc(atm.client_acc) mess = 'PIN changed\n1. Back\n' ses.send(mess, atm.atm) get_back(atm)
def tranfer_mony(atm): mess = 'Introduce account to transfer:\n' ses.send(mess, atm.atm) add_acc = ses.recv(atm.atm) mess = 'Introduce amount of money to transfer:\n' ses.send(mess, atm.atm) mony = ses.recv(atm.atm) update_balance(add_acc, float(mony)) update_balance(atm.client_card, -float(mony)) mess = 'Transfer done\n1. Back\n' ses.send(mess, atm.atm) get_back(atm) pass
def eject_card(atm): mess = 'Here is your card\n' + atm.client_card + '\n' ses.send(mess, atm.atm)
def resp(client, mess): ses.send(mess, client)
def chek_balance(atm): mess = 'Balance:\n' + atm.client_acc['balance'] mess += '\n1. Back\n' ses.send(mess, atm.atm) get_back(atm)
import p2_0_session as ses import sys if __name__ == "__main__": server = ses.start_sever("0.0.0.0", 1919) mess = ses.recv(server) print(mess) ses.send('ello too', server)
import p2_0_session as ses import sys if __name__ == "__main__": client = ses.connect_to("0.0.0.0", 1919) mess = 'hello there' ses.send(mess, client) file_text = ses.recv(client) print(file_text)