Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xlrd
- import random
- from xlutils.copy import copy
- from tabulate import *
- def Datos_dic_dic():
- f2 = sheet.nrows - 1
- for i in range(f2):
- Datos[str(int(sheet.cell_value(i+1, 0)))] = {}
- #Para DNI
- Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 1))] = str(int(sheet.cell_value(i+1, 1)))
- #Para APELLIDOS
- Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 2))] = str(sheet.cell_value(i+1, 2))
- #Para NOMBRES
- Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 3))] = str(sheet.cell_value(i+1, 3))
- #Para SALDO
- Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 4))] = str(int(sheet.cell_value(i+1, 4)))
- #Para ESTADO
- Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 5))] = str(sheet.cell_value(i+1, 5))
- #Para CONTRASEÑA
- Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 6))] = str(int(sheet.cell_value(i+1, 6)))
- print(Datos)
- return Datos
- def Cuentas_mov_dic_dic():
- g1 = movimientos.ncols
- for i in range(g1//3):
- lista_cuentas = []
- lista_montos = []
- lista_retiros = []
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))] = {}
- for m in movimientos.col_values(3*i):
- if m != '':
- lista_cuentas.append(str(int(m)))
- for h in movimientos.col_values((3*i)+1):
- if h != '':
- lista_montos.append(str(int(h)))
- for b in movimientos.col_values((3*i)+2):
- if b != '' and b != movimientos.cell_value(0, (3*i)+2):
- lista_retiros.append(str(int(b)))
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['CUENTA DESTINO'] = lista_cuentas
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['MONTO DEPOSITADO'] = lista_montos
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['RETIRO'] = lista_retiros
- print(Cuentas_mov)
- return Cuentas_mov
- def Aperturar_cuenta():
- g2 = movimientos.ncols
- f1 = sheet.nrows - 1
- cuentaran = str(random.randrange(999999))
- print('Por favor ingrese los datos solicitados...')
- print('Su nuevo número de cuenta es: ', cuentaran, end = '')
- print()
- dni = input('DNI: ')
- apellidos = input('Apellidos: ')
- nombres = input('Nombres: ')
- saldo = input('Saldo que abonará a su cuenta: ')
- estado = input('Estado de su cuenta (Bloqueada(B) o Activa(A)): ')
- if estado == 'B':
- estado = 'BLOQUEADA'
- else:
- estado = 'ACTIVA'
- contra = input('Ingrese su nueva contraseña (4 dígitos): ')
- Datos[cuentaran] = {}
- wb_sheet.write(f1+1, 0, cuentaran)
- Datos[cuentaran]['DNI'] = str(dni)
- wb_sheet.write(f1+1, 1, dni)
- Datos[cuentaran]['APELLIDOS'] = str(apellidos)
- wb_sheet.write(f1+1, 2, apellidos)
- Datos[cuentaran]['NOMBRES'] = str(nombres)
- wb_sheet.write(f1+1, 3, nombres)
- Datos[cuentaran]['SALDO'] = str(saldo)
- wb_sheet.write(f1+1, 4, saldo)
- Datos[cuentaran]['ESTADO'] = str(estado)
- wb_sheet.write(f1+1, 5, estado)
- Datos[cuentaran]['CONTRASENA'] = str(contra)
- wb_sheet.write(f1+1, 6, contra)
- wb_movimientos.write(0, g2 - 1 + 1, '.')
- wb_movimientos.write(0, g2 - 1 + 2, '.')
- wb_movimientos.write(0, g2 - 1 + 3, cuentaran)
- lista_cuentas = []
- lista_montos = []
- lista_retiros = []
- Cuentas_mov[cuentaran] = {}
- Cuentas_mov[cuentaran]['CUENTA DESTINO'] = lista_cuentas
- Cuentas_mov[cuentaran]['MONTO DEPOSITADO'] = lista_montos
- Cuentas_mov[cuentaran]['RETIRO'] = lista_retiros
- wb.save('BaseDatos.xls')
- Inicio()
- def Inicio():
- Datos_dic_dic()
- Cuentas_mov_dic_dic()
- bienvenida1 = 'BIENVENIDO AL BANCO BRICHE'
- print(bienvenida1.center(58, '~'))
- print('''
- 1) Ya tengo una cuenta 2) Aperturar una cuenta
- ''')
- print('Inserte una opción: ', end= '')
- inicio = int(input())
- print()
- if inicio == 2:
- Aperturar_cuenta()
- else:
- Verificar_datos()
- def Menu(numeroveri):
- Datos_dic_dic()
- Cuentas_mov_dic_dic()
- print('''
- 1) Realizar depósito 2) Realizar retiro 3) Bloquear/Desbloquear cuenta
- 4) Cerrar cuenta 5) Consultar cuenta 6) Movimientos
- ''')
- print('Inserte un número: ', end='')
- inicio = int(input())
- print()
- if inicio == 2:
- Realizarretiro(numeroveri)
- if inicio == 5:
- Consultar_cuenta(numeroveri)
- if inicio == 6:
- Consulta_movimientos(numeroveri)
- if inicio == 3:
- Bloq2desbloq(numeroveri)
- def Verificar_datos():
- print()
- numeroveri = str(input('Inserte su número de cuenta: '))
- print()
- dniveri = str(input('Inserte DNI: '))
- if numeroveri in Datos and Datos[numeroveri]['DNI'] == dniveri:
- print('Datos correctos')
- nombre_bienvenida = Datos[numeroveri]['NOMBRES']
- apellido_bienvenida = Datos[numeroveri]['APELLIDOS']
- print(f'Bienvenido {nombre_bienvenida} {apellido_bienvenida}')
- return Menu(numeroveri)
- else:
- print('Datos incorrectos')
- regres = input('¿Desea seguir intentando? (SI O NO): ')
- if regres == 'SI':
- return Verificar_datos()
- if regres == 'NO':
- print()
- print()
- return Inicio()
- while regres != 'SI' or regres != 'NO':
- regres = input('Coloque solamente SI O NO: ')
- if regres == 'SI':
- return Verificar_datos()
- if regres == 'NO':
- return Inicio()
- def Consultar_cuenta(numeroveri):
- ga = Datos[numeroveri]['CONTRASENA']
- del Datos[numeroveri]['CONTRASENA']
- keysstr = list(Datos[numeroveri].keys())
- valuesstr = []
- valuesstr.append(list(Datos[numeroveri].values()))
- Datos[numeroveri]['CONTRASENA'] = ga
- Contrasena(numeroveri)
- print()
- print(tabulate(list(valuesstr), headers=keysstr, tablefmt='fancy_grid', stralign='center', numalign='center'))
- print()
- cons = input('¿Desea continuar? ')
- if cons == 'SI':
- return Menu(numeroveri)
- if cons == 'NO':
- return Inicio()
- def Contrasena(numeroveri):
- print('Por favor digite su conraseña: ')
- valores_dat = list(Datos[numeroveri].values())
- contrares = input()
- if contrares == valores_dat[5]:
- return 'Contraseña correcta'
- else:
- print('Contraseña incorrecta')
- contrares_sn = input('¿Desea continuar? (SI O NO): ')
- if contrares_sn == 'SI':
- return Contrasena(numeroveri)
- if contrares_sn == 'NO':
- print()
- print()
- return Inicio()
- while contrares_sn != 'SI' or contrares_sn != 'NO':
- contrares_sn = input('Coloque solamente SI O NO: ')
- if contrares_sn == 'SI':
- return Contrasena(numeroveri)
- if contrares_sn == 'NO':
- return Inicio()
- def Consulta_movimientos(numeroveri):
- Contrasena(numeroveri)
- print()
- print('~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~')
- r = {}
- r['RETIRO'] = Cuentas_mov[numeroveri]['RETIRO']
- print(tabulate(r, headers=['RETIRO'], tablefmt='fancy_grid', showindex=True, stralign='center', numalign='center'))
- gu = Cuentas_mov[numeroveri]['RETIRO']
- del Cuentas_mov[numeroveri]['RETIRO']
- print(tabulate(Cuentas_mov[numeroveri], headers=list(Cuentas_mov[numeroveri]), tablefmt='fancy_grid', showindex=True, stralign='center', numalign='center'))
- Cuentas_mov[numeroveri]['RETIRO'] = gu
- print()
- iyni = input('Pulse tecla enter para continuar')
- print()
- print('~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~')
- print()
- return Menu(numeroveri)
- def Realizarretiro(numeroveri):
- print('Verificaremos el estado actual de su cuenta')
- Activopararetiro(numeroveri)
- print()
- Contrasena(numeroveri)
- print('Su saldo actual es ', Datos[numeroveri]['SALDO'])
- ret = int(input('Inserte la cantidad que desea retirar: '))
- if ret < int(Datos[numeroveri]['SALDO']):
- montoretiro(numeroveri, ret)
- if ret > Datos[numeroveri]['SALDO']:
- print('SALDO INSUFICIENTE')
- ret = input()
- while ret > Datos[numeroveri]['SALDO']:
- print('SALDO INSUFICIENTE')
- ret = input()
- if ret < Datos[numeroveri]['SALDO']:
- montoretiro(numeroveri, ret)
- def montoretiro(numeroveri, ret):
- gomi = (int(Datos[numeroveri]['SALDO']) - ret)
- Datos[numeroveri]['SALDO'] = str(gomi)
- nacho = (list(Datos.keys())).index(str(numeroveri))
- wb_sheet.write(nacho+1, 4, gomi)
- mascotcuenta = []
- mascotretiro = []
- caromascot = (((list(Cuentas_mov.keys())).index(numeroveri)) * 3) - 1
- for o in movimientos.col_values(caromascot):
- if o == '':
- mascotretiro.append(o)
- else:
- mascotretiro.append(str(int(o)))
- for a in movimientos.col_values(caromascot-1):
- if a == '' or a == '.':
- mascotcuenta.append(a)
- else:
- mascotcuenta.append(str(int(a)))
- if len(mascotcuenta) >= len(mascotretiro):
- wb_movimientos.write(len(mascotcuenta), caromascot, gomi)
- if len(mascotcuenta) < len(mascotretiro):
- wb_movimientos.write(len(mascotretiro), caromascot, gomi)
- wb.save('BaseDatos.xls')
- print()
- print('RETIRO EXITOSO')
- print()
- xxx = input('¿Desea continuar?: ')
- if xxx == 'SI':
- Menu(numeroveri)
- if xxx == 'NO':
- return Inicio()
- def Activopararetiro(numeroveri):
- if Datos[numeroveri]['ESTADO'] == 'ACTIVA':
- return 'Cuenta Activa'
- if Datos[numeroveri]['ESTADO'] == 'BLOQUEADA':
- print('No se puede hacer el retiro debido a que la cuenta está bloqueada')
- bloq = input('¿Desea desbloquear su cuenta?')
- if bloq == 'NO':
- return Menu(numeroveri)
- if bloq == 'SI':
- return Bloq2desbloq(numeroveri)
- if Datos[numeroveri]['ESTADO'] == 'CERRADA':
- print('Su cuenta está cerrada')
- print('Si desea activarla tiene que acercarse al banco más cercano')
- print('De lo contrario no podrá realizar otra operación,')
- print('salvo que recien haya cerrado su cuenta y deba retirar todo su dinero.')
- print()
- return Menu(numeroveri)
- def Bloq2desbloq(numeroveri):
- print('Para desbloquear su cuenta necesitamos su contraseña de 4 dígitos' + '\n')
- passw = input('Por favor ingrésela a continuación: ')
- if passw == Datos[numeroveri]['CONTRASENA']:
- Datos[numeroveri]['ESTADO'] = 'ACTIVA'
- nh = list(Datos.keys()).index(numeroveri)
- wb_sheet.write(nh+1, 5, 'ACTIVA')
- wb.save('BaseDatos.xls')
- print()
- print('Proceso de cambio finalizado')
- print()
- return Menu(numeroveri)
- else:
- print('Contraseña incorrecta')
- rg = input('¿Desea seguir intentando? (SI O NO): ')
- if rg == 'SI':
- return Bloq2desbloq(numeroveri)
- if rg == 'NO':
- print()
- print()
- return Menu(numeroveri)
- while rg != 'SI' or rg != 'NO':
- rg = input('Coloque solamente SI O NO: ')
- if rg == 'SI':
- return Bloq2desbloq(numeroveri)
- if rg == 'NO':
- return Menu(numeroveri)
- def Cuentas_mov_dic_dic():
- g1 = movimientos.ncols
- for i in range(g1//3):
- lista_cuentas = []
- lista_montos = []
- lista_retiros = []
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))] = {}
- for m in movimientos.col_values(3*i):
- if m != '' and m != '.':
- lista_cuentas.append(str(int(m)))
- for h in movimientos.col_values((3*i)+1):
- if h != '' and h != '.':
- lista_montos.append(str(int(h)))
- for b in movimientos.col_values((3*i)+2):
- if b != '' and b != movimientos.cell_value(0, (3*i)+2):
- lista_retiros.append(str(int(b)))
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['CUENTA DESTINO'] = lista_cuentas
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['MONTO DEPOSITADO'] = lista_montos
- Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['RETIRO'] = lista_retiros
- print(Cuentas_mov)
- return Cuentas_mov
- #def Desbloq2bloq(numeroveri)
- file_loc = 'BaseDatos.xls'
- workbook = xlrd.open_workbook(file_loc)
- sheet = workbook.sheet_by_index(0)
- #PARA HOJA MOVIMIENTO MODIFICAR
- movimientos = workbook.sheet_by_index(1)
- wb = copy(workbook)
- wb_sheet = wb.get_sheet(0)
- #PARA HOJA MOVIMIENTOS MODIFICAR
- wb_movimientos = wb.get_sheet(1)
- Datos = {}
- Cuentas_mov = {}
- Inicio()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement