60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
from validacion import *
|
|
from variables import *
|
|
|
|
def normalizar_instante(instante, formato):
|
|
d = validarInstante(instante)
|
|
if d is None:
|
|
return None
|
|
|
|
if formato == 1:
|
|
if not d['mes'].isdigit():
|
|
d['mes'] = meses.index(d['mes'].lower()) + 1
|
|
return f"{d['año']}-{d['mes']:0>2}-{d['dia']:0>2} {d['hora']:0>2}:{d['minuto']}"
|
|
|
|
elif formato == 2:
|
|
if d['mes'] in meses:
|
|
return f"{d['mes']} {d['dia']}, {d['año']} {d['hora']}:{d['minuto']} {d['segundo']}"
|
|
else:
|
|
if int(d['hora']) > 12:
|
|
d['hora'] = int(d['hora']) % 12
|
|
|
|
if d['mes'].isdigit():
|
|
d['mes'] = meses[int(d['mes']) - 1]
|
|
|
|
return f"{d['mes'].lower()} {d['dia']}, {d['año']} {d['hora']}:{d['minuto']} AM"
|
|
|
|
elif formato == 3:
|
|
if not d['mes'].isdigit():
|
|
d['mes'] = meses.index(d['mes'].lower()) + 1
|
|
|
|
if not d['segundo'].isdigit():
|
|
d['segundo'] = '00'
|
|
return f"{d['hora']}:{d['minuto']}:{d['segundo']} {d['dia']}/{d['mes']}/{d['año']}"
|
|
|
|
|
|
def normalizar_telefono(telefono):
|
|
telefono = re.sub(r'( )|(-)', r'', telefono)
|
|
if telefono[0] != '+':
|
|
return f'+34{telefono}'
|
|
return telefono
|
|
|
|
def normalizar_coordenada(coordenada, formato):
|
|
c = validarCoordenada(coordenada, formato)
|
|
return c
|
|
|
|
def normalizar(fichero, formato_fecha, formato_coordenadas):
|
|
try:
|
|
f = open(fichero, 'r')
|
|
except:
|
|
exit(1)
|
|
n = 0
|
|
for i in f.readlines():
|
|
telefono, nif, instante, coordenada, producto, precio = i.split(";")
|
|
instante = normalizar_instante(instante.strip(), 1)
|
|
telefono = normalizar_telefono(telefono.strip())
|
|
coordenada = normalizar_coordenada(coordenada.strip(), 3)
|
|
print(instante, telefono, coordenada)
|
|
n += 1
|
|
|
|
print(n)
|