Bot 2: Script funcional para el procesamiento y filtrado de los archivos descargados
This commit is contained in:
@@ -36,19 +36,19 @@ def recorrer_y_parsear(directorio_raiz=BASE_DIR):
|
||||
"""
|
||||
registros = []
|
||||
|
||||
for carpeta_actual, _subcarpetas, archivos in os.walk(directorio_raiz):
|
||||
for nombre in archivos:
|
||||
for carpeta_actual, _subcarpetas, archivos in sorted(os.walk(directorio_raiz)):
|
||||
for nombre in sorted(archivos):
|
||||
if not nombre.lower().endswith(".txt"):
|
||||
continue
|
||||
|
||||
ruta_txt = os.path.join(carpeta_actual, nombre)
|
||||
try:
|
||||
with open(ruta_txt, "r", encoding="latin-1") as f:
|
||||
with open(ruta_txt, "r", encoding="utf-8") as f:
|
||||
for linea in f:
|
||||
registro = _parsear_linea(linea, nombre)
|
||||
if registro:
|
||||
registros.append(registro)
|
||||
except OSError as e:
|
||||
except (OSError, UnicodeDecodeError) as e:
|
||||
logger.error("No se pudo leer %s: %s", ruta_txt, e)
|
||||
|
||||
logger.info("Total de registros parseados: %d", len(registros))
|
||||
|
||||
Reference in New Issue
Block a user