Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.89 KB | None | 0 0
  1. import xlrd
  2. import random
  3. from xlutils.copy import copy
  4. from tabulate import *
  5. def Datos_dic_dic():
  6.     f2 = sheet.nrows - 1
  7.     for i in range(f2):
  8.         Datos[str(int(sheet.cell_value(i+1, 0)))] = {}
  9.         #Para DNI
  10.         Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 1))] = str(int(sheet.cell_value(i+1, 1)))
  11.         #Para APELLIDOS
  12.         Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 2))] = str(sheet.cell_value(i+1, 2))
  13.         #Para NOMBRES
  14.         Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 3))] = str(sheet.cell_value(i+1, 3))
  15.         #Para SALDO
  16.         Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 4))] = str(int(sheet.cell_value(i+1, 4)))
  17.         #Para ESTADO
  18.         Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 5))] = str(sheet.cell_value(i+1, 5))
  19.         #Para CONTRASEÑA
  20.         Datos[str(int(sheet.cell_value(i+1, 0)))][str(sheet.cell_value(0, 6))] = str(int(sheet.cell_value(i+1, 6)))
  21.     print(Datos)
  22.     return Datos
  23. def Cuentas_mov_dic_dic():
  24.     g1 = movimientos.ncols
  25.     for i in range(g1//3):
  26.         lista_cuentas = []
  27.         lista_montos = []
  28.         lista_retiros = []
  29.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))] = {}
  30.         for m in movimientos.col_values(3*i):
  31.             if m != '':
  32.                 lista_cuentas.append(str(int(m)))
  33.         for h in movimientos.col_values((3*i)+1):
  34.             if h != '':
  35.                 lista_montos.append(str(int(h)))
  36.         for b in movimientos.col_values((3*i)+2):
  37.             if b != '' and b != movimientos.cell_value(0, (3*i)+2):
  38.                 lista_retiros.append(str(int(b)))
  39.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['CUENTA DESTINO'] = lista_cuentas
  40.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['MONTO DEPOSITADO'] = lista_montos
  41.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['RETIRO'] = lista_retiros
  42.     print(Cuentas_mov)
  43.     return Cuentas_mov
  44. def Aperturar_cuenta():
  45.     g2 = movimientos.ncols
  46.     f1 = sheet.nrows - 1
  47.     cuentaran = str(random.randrange(999999))
  48.     print('Por favor ingrese los datos solicitados...')
  49.     print('Su nuevo número de cuenta es: ', cuentaran, end = '')
  50.     print()
  51.     dni = input('DNI: ')
  52.     apellidos = input('Apellidos: ')
  53.     nombres = input('Nombres: ')
  54.     saldo = input('Saldo que abonará a su cuenta: ')
  55.     estado = input('Estado de su cuenta (Bloqueada(B) o Activa(A)): ')
  56.     if estado == 'B':
  57.         estado = 'BLOQUEADA'
  58.     else:
  59.         estado = 'ACTIVA'
  60.     contra = input('Ingrese su nueva contraseña (4 dígitos): ')
  61.     Datos[cuentaran] = {}
  62.     wb_sheet.write(f1+1, 0, cuentaran)
  63.     Datos[cuentaran]['DNI'] = str(dni)
  64.     wb_sheet.write(f1+1, 1, dni)
  65.     Datos[cuentaran]['APELLIDOS'] = str(apellidos)
  66.     wb_sheet.write(f1+1, 2, apellidos)
  67.     Datos[cuentaran]['NOMBRES'] = str(nombres)
  68.     wb_sheet.write(f1+1, 3, nombres)
  69.     Datos[cuentaran]['SALDO'] = str(saldo)
  70.     wb_sheet.write(f1+1, 4, saldo)
  71.     Datos[cuentaran]['ESTADO'] = str(estado)
  72.     wb_sheet.write(f1+1, 5, estado)
  73.     Datos[cuentaran]['CONTRASENA'] = str(contra)
  74.     wb_sheet.write(f1+1, 6, contra)
  75.     wb_movimientos.write(0, g2 - 1 + 1, '.')
  76.     wb_movimientos.write(0, g2 - 1 + 2, '.')
  77.     wb_movimientos.write(0, g2 - 1 + 3, cuentaran)
  78.     lista_cuentas = []
  79.     lista_montos = []
  80.     lista_retiros = []
  81.     Cuentas_mov[cuentaran] = {}
  82.     Cuentas_mov[cuentaran]['CUENTA DESTINO'] = lista_cuentas
  83.     Cuentas_mov[cuentaran]['MONTO DEPOSITADO'] = lista_montos
  84.     Cuentas_mov[cuentaran]['RETIRO'] = lista_retiros
  85.     wb.save('BaseDatos.xls')
  86.     Inicio()
  87. def Inicio():
  88.     Datos_dic_dic()
  89.     Cuentas_mov_dic_dic()
  90.     bienvenida1 = 'BIENVENIDO AL BANCO BRICHE'
  91.     print(bienvenida1.center(58, '~'))
  92.     print('''
  93.       1) Ya tengo una cuenta      2) Aperturar una cuenta
  94.       ''')
  95.     print('Inserte una opción:  ', end= '')
  96.     inicio = int(input())
  97.     print()
  98.     if inicio == 2:
  99.         Aperturar_cuenta()
  100.     else:
  101.         Verificar_datos()
  102. def Menu(numeroveri):
  103.     Datos_dic_dic()
  104.     Cuentas_mov_dic_dic()
  105.     print('''
  106.       1) Realizar depósito      2) Realizar retiro      3) Bloquear/Desbloquear cuenta
  107.       4) Cerrar cuenta          5) Consultar cuenta     6) Movimientos
  108.       ''')
  109.     print('Inserte un número: ', end='')
  110.     inicio = int(input())
  111.     print()
  112.     if inicio == 2:
  113.         Realizarretiro(numeroveri)
  114.     if inicio == 5:
  115.         Consultar_cuenta(numeroveri)
  116.     if inicio == 6:
  117.         Consulta_movimientos(numeroveri)
  118.     if inicio == 3:
  119.         Bloq2desbloq(numeroveri)
  120. def Verificar_datos():
  121.     print()
  122.     numeroveri = str(input('Inserte su número de cuenta:    '))
  123.     print()
  124.     dniveri = str(input('Inserte DNI:   '))
  125.     if numeroveri in Datos and Datos[numeroveri]['DNI'] == dniveri:
  126.             print('Datos correctos')
  127.             nombre_bienvenida = Datos[numeroveri]['NOMBRES']
  128.             apellido_bienvenida = Datos[numeroveri]['APELLIDOS']
  129.             print(f'Bienvenido {nombre_bienvenida} {apellido_bienvenida}')
  130.             return Menu(numeroveri)
  131.     else:
  132.         print('Datos incorrectos')
  133.         regres = input('¿Desea seguir intentando? (SI O NO): ')
  134.         if regres == 'SI':
  135.             return Verificar_datos()
  136.         if regres == 'NO':
  137.             print()
  138.             print()
  139.             return Inicio()
  140.         while regres != 'SI' or regres != 'NO':
  141.             regres = input('Coloque solamente SI O NO:  ')
  142.             if regres == 'SI':
  143.                 return Verificar_datos()
  144.             if regres == 'NO':
  145.                 return Inicio()
  146. def Consultar_cuenta(numeroveri):
  147.     ga = Datos[numeroveri]['CONTRASENA']
  148.     del Datos[numeroveri]['CONTRASENA']
  149.     keysstr = list(Datos[numeroveri].keys())
  150.     valuesstr = []
  151.     valuesstr.append(list(Datos[numeroveri].values()))
  152.     Datos[numeroveri]['CONTRASENA'] = ga
  153.     Contrasena(numeroveri)
  154.     print()
  155.     print(tabulate(list(valuesstr), headers=keysstr, tablefmt='fancy_grid', stralign='center', numalign='center'))
  156.     print()
  157.     cons = input('¿Desea continuar?   ')
  158.     if cons == 'SI':
  159.         return Menu(numeroveri)
  160.     if cons == 'NO':
  161.         return Inicio()
  162. def Contrasena(numeroveri):
  163.     print('Por favor digite su conraseña: ')
  164.     valores_dat = list(Datos[numeroveri].values())
  165.     contrares = input()
  166.     if contrares == valores_dat[5]:
  167.         return 'Contraseña correcta'
  168.     else:
  169.         print('Contraseña incorrecta')
  170.         contrares_sn = input('¿Desea continuar? (SI O NO): ')
  171.         if contrares_sn == 'SI':
  172.             return Contrasena(numeroveri)
  173.         if contrares_sn == 'NO':
  174.             print()
  175.             print()
  176.             return Inicio()
  177.         while contrares_sn != 'SI' or contrares_sn != 'NO':
  178.             contrares_sn = input('Coloque solamente SI O NO:  ')
  179.             if contrares_sn == 'SI':
  180.                 return Contrasena(numeroveri)
  181.             if contrares_sn == 'NO':
  182.                 return Inicio()
  183. def Consulta_movimientos(numeroveri):
  184.     Contrasena(numeroveri)
  185.     print()
  186.     print('~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~')
  187.     r = {}
  188.     r['RETIRO'] = Cuentas_mov[numeroveri]['RETIRO']
  189.     print(tabulate(r, headers=['RETIRO'], tablefmt='fancy_grid', showindex=True, stralign='center', numalign='center'))
  190.     gu = Cuentas_mov[numeroveri]['RETIRO']
  191.     del Cuentas_mov[numeroveri]['RETIRO']
  192.     print(tabulate(Cuentas_mov[numeroveri], headers=list(Cuentas_mov[numeroveri]), tablefmt='fancy_grid', showindex=True, stralign='center', numalign='center'))
  193.     Cuentas_mov[numeroveri]['RETIRO'] = gu
  194.     print()
  195.     iyni = input('Pulse tecla enter para continuar')
  196.     print()
  197.     print('~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~')
  198.     print()
  199.     return Menu(numeroveri)
  200. def Realizarretiro(numeroveri):
  201.     print('Verificaremos el estado actual de su cuenta')
  202.     Activopararetiro(numeroveri)
  203.     print()
  204.     Contrasena(numeroveri)
  205.     print('Su saldo actual es    ', Datos[numeroveri]['SALDO'])
  206.     ret = int(input('Inserte la cantidad que desea retirar:   '))
  207.     if ret < int(Datos[numeroveri]['SALDO']):
  208.         montoretiro(numeroveri, ret)
  209.     if ret > Datos[numeroveri]['SALDO']:
  210.         print('SALDO INSUFICIENTE')
  211.         ret = input()
  212.         while ret > Datos[numeroveri]['SALDO']:
  213.             print('SALDO INSUFICIENTE')
  214.             ret = input()
  215.         if ret < Datos[numeroveri]['SALDO']:
  216.             montoretiro(numeroveri, ret)
  217. def montoretiro(numeroveri, ret):
  218.     gomi = (int(Datos[numeroveri]['SALDO']) - ret)
  219.     Datos[numeroveri]['SALDO'] = str(gomi)
  220.     nacho = (list(Datos.keys())).index(str(numeroveri))
  221.     wb_sheet.write(nacho+1, 4, gomi)
  222.     mascotcuenta = []
  223.     mascotretiro = []
  224.     caromascot = (((list(Cuentas_mov.keys())).index(numeroveri)) * 3) - 1
  225.     for o in movimientos.col_values(caromascot):
  226.         if o == '':
  227.             mascotretiro.append(o)
  228.         else:
  229.             mascotretiro.append(str(int(o)))
  230.     for a in movimientos.col_values(caromascot-1):
  231.         if a == '' or a == '.':
  232.             mascotcuenta.append(a)
  233.         else:
  234.             mascotcuenta.append(str(int(a)))
  235.     if len(mascotcuenta) >= len(mascotretiro):
  236.         wb_movimientos.write(len(mascotcuenta), caromascot, gomi)
  237.     if len(mascotcuenta) < len(mascotretiro):
  238.         wb_movimientos.write(len(mascotretiro), caromascot, gomi)
  239.     wb.save('BaseDatos.xls')
  240.     print()
  241.     print('RETIRO EXITOSO')
  242.     print()
  243.     xxx = input('¿Desea continuar?: ')
  244.     if xxx == 'SI':
  245.         Menu(numeroveri)
  246.     if xxx == 'NO':
  247.         return Inicio()
  248. def Activopararetiro(numeroveri):
  249.     if Datos[numeroveri]['ESTADO'] == 'ACTIVA':
  250.         return 'Cuenta Activa'
  251.     if Datos[numeroveri]['ESTADO'] == 'BLOQUEADA':
  252.         print('No se puede hacer el retiro debido a que la cuenta está bloqueada')
  253.         bloq = input('¿Desea desbloquear su cuenta?')
  254.         if bloq == 'NO':
  255.             return Menu(numeroveri)
  256.         if bloq == 'SI':
  257.             return Bloq2desbloq(numeroveri)
  258.     if Datos[numeroveri]['ESTADO'] == 'CERRADA':
  259.         print('Su cuenta está cerrada')
  260.         print('Si desea activarla tiene que acercarse al banco más cercano')
  261.         print('De lo contrario no podrá realizar otra operación,')
  262.         print('salvo que recien haya cerrado su cuenta y deba retirar todo su dinero.')
  263.         print()
  264.         return Menu(numeroveri)
  265. def Bloq2desbloq(numeroveri):
  266.     print('Para desbloquear su cuenta necesitamos su contraseña de 4 dígitos' + '\n')
  267.     passw = input('Por favor ingrésela a continuación:   ')
  268.     if passw == Datos[numeroveri]['CONTRASENA']:
  269.         Datos[numeroveri]['ESTADO'] = 'ACTIVA'
  270.         nh = list(Datos.keys()).index(numeroveri)
  271.         wb_sheet.write(nh+1, 5, 'ACTIVA')
  272.         wb.save('BaseDatos.xls')
  273.         print()
  274.         print('Proceso de cambio finalizado')
  275.         print()
  276.         return Menu(numeroveri)
  277.     else:
  278.         print('Contraseña incorrecta')
  279.         rg = input('¿Desea seguir intentando? (SI O NO): ')
  280.         if rg == 'SI':
  281.             return Bloq2desbloq(numeroveri)
  282.         if rg == 'NO':
  283.             print()
  284.             print()
  285.             return Menu(numeroveri)
  286.         while rg != 'SI' or rg != 'NO':
  287.             rg = input('Coloque solamente SI O NO:  ')
  288.             if rg == 'SI':
  289.                 return Bloq2desbloq(numeroveri)
  290.             if rg == 'NO':
  291.                 return Menu(numeroveri)
  292. def Cuentas_mov_dic_dic():
  293.     g1 = movimientos.ncols
  294.     for i in range(g1//3):
  295.         lista_cuentas = []
  296.         lista_montos = []
  297.         lista_retiros = []
  298.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))] = {}
  299.         for m in movimientos.col_values(3*i):
  300.             if m != '' and m != '.':
  301.                 lista_cuentas.append(str(int(m)))
  302.         for h in movimientos.col_values((3*i)+1):
  303.             if h != '' and h != '.':
  304.                 lista_montos.append(str(int(h)))
  305.         for b in movimientos.col_values((3*i)+2):
  306.             if b != '' and b != movimientos.cell_value(0, (3*i)+2):
  307.                 lista_retiros.append(str(int(b)))
  308.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['CUENTA DESTINO'] = lista_cuentas
  309.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['MONTO DEPOSITADO'] = lista_montos
  310.         Cuentas_mov[str(int(movimientos.cell_value(0, (3*i)+2)))]['RETIRO'] = lista_retiros
  311.     print(Cuentas_mov)
  312.     return Cuentas_mov
  313.  
  314. #def Desbloq2bloq(numeroveri)
  315.  
  316.  
  317. file_loc = 'BaseDatos.xls'
  318. workbook = xlrd.open_workbook(file_loc)
  319. sheet = workbook.sheet_by_index(0)
  320. #PARA HOJA MOVIMIENTO MODIFICAR
  321. movimientos = workbook.sheet_by_index(1)
  322. wb = copy(workbook)
  323. wb_sheet = wb.get_sheet(0)
  324. #PARA HOJA MOVIMIENTOS MODIFICAR
  325. wb_movimientos = wb.get_sheet(1)
  326. Datos = {}
  327. Cuentas_mov = {}
  328. Inicio()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement