From 10b4e8cf2037c7b75705dce245e9d6c8ab7c3d2f Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 6 Mar 2026 13:51:05 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20resumen=20final=20de=20descargas?= =?UTF-8?q?=20al=20terminar=20o=20interrumpir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- main.py | 4 +++- zxdb/downloader.py | 7 +++++++ zxdb/filesystem.py | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index ff5ef58..1c56d1a 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/zxdb/downloader.py b/zxdb/downloader.py index 42a5d71..c88c641 100644 --- a/zxdb/downloader.py +++ b/zxdb/downloader.py @@ -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 diff --git a/zxdb/filesystem.py b/zxdb/filesystem.py index a4ef544..e5101df 100644 --- a/zxdb/filesystem.py +++ b/zxdb/filesystem.py @@ -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.