from datetime import datetime
import re
archivo = ['00014 - 05/12/2021 - Medidor EPE - 13125 - 8',
'00015 - 06/12/2021 - Medidor EPE - 13132 - 7',
'00016 - 07/12/2021 - Medidor EPE - 13140 - 8',
'00017 - 08/12/2021 - Medidor EPE - 13146 - 6',
'00018 - 09/12/2021 - Medidor EPE - 13153 - 7',
'00019 - 10/12/2021 - Medidor EPE - 13160 - 7',
'00020 - 11/12/2021 - Medidor EPE - 13169 - 9'
]
while True:
f1 = input('\n Fechas inicio, formato(dd/mm/aaaa)...: ')
try:
fecha_inicio = datetime.strptime(f1, '%d/%m/%Y')
except ValueError:
print("\n No ha ingresado una fecha correcta...")
else:
break
while True:
f2 = input('\n Fechas final, formato(dd/mm/aaaa)....: ')
try:
fecha_fin = datetime.strptime(f2, '%d/%m/%Y')
except ValueError:
print("\n No ha ingresado una fecha correcta...")
else:
break
if fecha_inicio > fecha_fin:
tmp = fecha_inicio
fecha_inicio = fecha_fin
fecha_fin = tmp
for linea in archivo:
fecha_str = linea[8:18]
fecha = datetime.strptime(fecha_str, '%d/%m/%Y')
if fecha >= fecha_inicio and fecha <= fecha_fin:
print(linea)