Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import time
- import random
- class ClearScreen:
- def __call__(self):
- if sys.platform.startswith('win32'):
- os.system('cls')
- elif sys.platform.startswith('darwin'):
- os.system('clear')
- elif sys.platform.startswith('cygwin') or sys.platform.startswith('linux'):
- os.system('clear')
- else:
- print('Trying clear', end='')
- for i in range(10):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.010)
- os.system('clear')
- clear = ClearScreen()
- class Cliente:
- def __init__(self, nome, cpf, rg, data_nascimento, telefone, endereco, dinheiro=0):
- self.__id = self.gerar()
- self.__conta = self.gerar()
- self.__senha = self.gerar()
- self.nome = nome
- self.__cpf = cpf
- self.__rg = rg
- self.__data_nasc = data_nascimento
- self.__tel = telefone
- self.__end = endereco
- self.__din = dinheiro
- @staticmethod
- def gerar():
- """
- GERA UM NÚMERO ALEATÓRIO PARA SER UTILIZADO POR VARIÁVEIS ACIMA
- """
- return(random.randint(0, 10**10))
- def validar_dados(self):
- """
- AQUI VALIDAMOS OS DADOS DE FORMA RÁPIDA E SIMPLES
- NÃO HÁ VERIFICAÇÃO SE O CPF É VÁLIDO OU NÃO, ETC.
- """
- v_cpf = len(self.__cpf) == 11
- v_data_nasc = len(self.__data_nasc.replace('/', '')) == 6 or len(self.__data_nasc.replace('/', '')) == 8
- v_tel = len(self.__tel.replace('-', '')) == 8 or len(self.__tel.replace('-', '')) == 9 \
- or len(self.__tel.replace('-', '')) == 10 or len(self.__tel.replace('-', '')) == 11
- v_end = self.__end.upper().startswith('R') or self.__end.upper().startswith('RUA') \
- or self.__end.upper().startswith('AV') or self.__end.upper().startswith('AVENIDA')
- count = 0
- for i in [v_cpf, v_end, v_data_nasc, v_tel]:
- if i == True:
- count += 1
- return True if count == 4 else False
- def acessar_banco(self):
- """
- O ACESSO DE TODO USUÁRIO DO BANCO PASSARÁ POR AQUI
- """
- nome, conta, agencia = self.consultar_dados()
- print("Usuário: %s\nConta: %d\nAgência: %d\n" % (nome, conta, agencia))
- escolha = int(input("[1] - Sacar dinheiro\n[2] - Ver extrato\n[3] - Depositar\n[4] - Sair\nentrada: "))
- print()
- if escolha == 1:
- print('Entrando na seção para sacar dinheiro', end='')
- for i in range(30):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.009)
- else:
- print()
- self.sacar()
- elif escolha == 2:
- print('Acessando extrato', end='')
- for i in range(30):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.009)
- else:
- print()
- self.extrato()
- elif escolha == 3:
- print('Acessando área para depósito em conta', end='')
- for i in range(30):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.009)
- else:
- print()
- self.depositar()
- else:
- print('Saindo do sistema', end='')
- for i in range(25):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.009)
- else:
- sys.exit(0)
- def sacar(self):
- """
- FUNÇÃO FEITA PRA SACAR DINHEIRO DO CLIENTE
- """
- ced_100, ced_50, ced_20, ced_10, ced_5, ced_2 = 0, 0, 0, 0, 0, 0
- quantias = [self.__din//5, self.__din//2.5, self.__din//2]
- escolhas = print("1 - %d\n2 - %d\n3 - %d\n" % (quantias[0], quantias[1], quantias[2]))
- quantia = int(input("Digite a quantia: "))
- quantia = quantias[quantia-1]
- if quantia in quantias:
- while quantia >= 100:
- ced_100 += 1
- quantia -= 100
- while quantia >= 50:
- ced_50 += 1
- quantia -= 50
- while quantia >= 20:
- ced_20 += 1
- quantia -= 20
- while quantia >= 10:
- ced_10 += 1
- quantia -= 10
- while quantia >= 5:
- ced_5 += 1
- quantia -= 5
- else:
- print("Não foi possível sacar, nos desculpe.\nSaldo insuficiente.")
- cedulas = {'100' : ced_100, '50' : ced_50, '20' : ced_20, '10' : ced_10, '5' : ced_5, '2' : ced_2}
- for chave in cedulas:
- if cedulas[chave] > 0:
- print("Você tirará %d notas de %s\n" % (cedulas[chave], chave))
- def extrato(self):
- """
- PRINTA O EXTRATO DO USUÁRIO, PRO FUTURO, SE PRECISO, PODE RETORNAR O SELF.__din
- """
- print("O usuário: %s tem exatamente %.2f reais" % (self.nome, self.__din))
- def consultar_dados(self):
- """
- Informação organizada da seguinte forma, conta, nome, cpf, rg, data_nasc, tel, end
- """
- with open('stats.dat', 'a+') as file:
- file.write('{}|{}/{},{}.{}*{}-{}+{}&{}\n' \
- .format(self.__conta, self.__senha, self.nome, self.__cpf, self.__rg, self.__data_nasc, self.__tel, self.__end, self.__din))
- return(self.nome, self.__conta, 1)
- def verificar(conta_u, senha_u):
- """
- VERIFICAÇÃO DE TODA CONTA DE USUÁRIO PASSARÁ POR AQUI
- """
- with open('stats.dat', 'r') as file:
- lines = file.readlines()
- for line in lines:
- eta = line.find('|')
- conta = line[:eta:]
- senha = line[eta+1:line.find('/'):]
- if conta_u == conta and senha_u == senha:
- nome = line[line.find('/')+1:line.find(','):]
- cpf = line[line.find(',')+1:line.find('.'):]
- rg = line[line.find('.')+1:line.find('*'):]
- data_nascimento = line[line.find('*')+1:line.find('-'):]
- tel = line[line.find('-')+1:line.find('+'):]
- end = line[line.find('+')+1:line.find('&'):]
- din = line[line.find('&')+1::]
- cliente = Cliente(nome, cpf, rg, data_nascimento, tel, end, din)
- cliente.acessar_banco()
- return(True)
- else:
- return(False)
- def main():
- """
- FUNÇÃO PRINCIPAL QUE TODO USUÁRIO SERÁ REDIRECIONADO
- """
- clear()
- if len(sys.argv) < 2:
- conta_u = input("Conta: ")
- senha_u = input("Senha: ")
- print()
- ver = verificar(conta_u, senha_u)
- if ver:
- print("Acessou com sucesso")
- else:
- print("Dados incorretos")
- else:
- # Bloco de instrução para criar conta :D
- if sys.argv[1] == '-c':
- print("Entrando no menu para criar conta", end='')
- for i in range(20):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.009)
- print()
- nome = input("Nome: ").title()
- if len(nome) < 1:
- main()
- cpf = input("CPF: ")
- if len(cpf) < 1:
- main()
- rg = input("RG: ")
- if len(rg) < 1:
- main()
- data_nascimento = input("Data de nascimento: ")
- if len(data_nascimento) < 1:
- main()
- telefone = input("Telefone: ")
- if len(telefone) < 1:
- main()
- endereco = input("Endereço: ")
- if len(endereco) < 1:
- main()
- cliente = Cliente(nome, cpf, rg, data_nascimento, telefone, endereco)
- while 1:
- cliente.acessar_banco()
- elif sys.argv[1] == '-h' or sys.argv[1] == '-help':
- print("Se o argumento sucedendo o py banco.py for -c, irá abrir um menu para criar uma conta.\nSenão \
- ele irá diretamente ao menu principal, pedindo informações como conta e senha para você entrar no sistema.\n")
- return('help')
- else:
- print("%s inválido e/ou inesperado. Desculpe-nos.\n" % (sys.argv[1].title()))
- if __name__ == '__main__':
- try:
- main()
- except KeyboardInterrupt:
- clear()
- print('Exiting', end='')
- for i in range(27):
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(.010)
- else:
- sys.exit(0)
Add Comment
Please, Sign In to add comment