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.