Añadido resumen final de descargas al terminar o interrumpir

Muestra contadores de ficheros por estado (caché, descargados,
no encontrados, omitidos) tanto al finalizar normalmente como
al interrumpir con Ctrl+C.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 13:51:05 +01:00
parent f967af541c
commit 10b4e8cf20
3 changed files with 18 additions and 1 deletions
+3 -1
View File
@@ -10,6 +10,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
def main():
stats = {}
try:
if run_setup() != 0:
sys.exit(1)
@@ -18,9 +19,10 @@ def main():
elements = organizer.process_elements(elements)
filesystem.print_elements(elements, mode=1)
filesystem.clear_destination_folder()
downloader.get_files(elements)
stats = downloader.get_files(elements)
filesystem.remove_empty_directories(config.DESTINATION_PATH)
finally:
filesystem.print_summary(stats)
stop_container(CONTAINER_NAME)
+7
View File
@@ -94,6 +94,7 @@ def get_files(elements):
Parámetros:
elements (list): Lista de diccionarios con la información de cada fichero a procesar.
"""
stats = {"cached": 0, "downloaded": 0, "not_found": 0, "skipped": 0}
current_file = 0
total_files = len(elements)
total_files_width = len(str(total_files))
@@ -122,10 +123,12 @@ def get_files(elements):
if os.path.isfile(cache_file):
process_cache_file(cache_file, destination_subfolder, destination_file, element)
print_status(current_file, total_files, element, total_files_width, status="cached")
stats["cached"] += 1
else:
if download_file(element["url"], config.TEMP_FILE):
print_status(current_file, total_files, element, total_files_width, status="downloaded")
stats["downloaded"] += 1
if os.path.isfile(config.TEMP_FILE):
os.makedirs(cache_subfolder, exist_ok=True)
shutil.move(config.TEMP_FILE, cache_file)
@@ -133,12 +136,16 @@ def get_files(elements):
process_cache_file(cache_file, destination_subfolder, destination_file, element)
else:
print_status(current_file, total_files, element, total_files_width, status="not found")
stats["not_found"] += 1
if config.WAIT:
time.sleep(random.randint(config.MIN_WAIT, config.MAX_WAIT))
else:
print_status(current_file, total_files, element, total_files_width, status="skipping")
stats["skipped"] += 1
except Exception as e:
logging.error(f"Error al procesar el fichero {element['file_name']}: {e}")
return stats
+8
View File
@@ -72,6 +72,14 @@ def clear_destination_folder():
logging.error(f'No se pudo eliminar {file_path}. Razón: {e}')
def print_summary(stats: dict) -> None:
print("\n--- Resumen ---")
print(f" Caché: {stats.get('cached', 0)}")
print(f" Descargados: {stats.get('downloaded', 0)}")
print(f" No encontrados: {stats.get('not_found', 0)}")
print(f" Omitidos: {stats.get('skipped', 0)}")
def remove_empty_directories(path):
"""
Elimina los subdirectorios vacíos de forma recursiva.