import os import shutil import re import unicodedata import logging import csv from PIL…
- User
import os import shutil import re import unicodedata import logging import csv from PIL import Image, ExifTags import piexif
----------------------------------------------------------------------------------------------------------------------
Configuration
----------------------------------------------------------------------------------------------------------------------
Configure logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
Define file paths (Update these paths as needed)
folder_path = r'C:\Users\anhb3\Desktop\long\test\Thời trang quyến rũ' # For Image Processing html_folder_path = r'C:\Users\anhb3\Desktop\long\test\Thời trang quyến rũ' # For HTML Processing csv_file_path = r'C:\Users\anhb3\Desktop\long\chen_anh.csv' # CSV for Image HTML links_file_path = r'C:\Users\anhb3\Desktop\long\di_link.txt' # TXT for Links
----------------------------------------------------------------------------------------------------------------------
Image Processing Functions
----------------------------------------------------------------------------------------------------------------------
def is_image_readable(file_path): """ Check if an image file is readable.
codeArgs: file_path (str): Path to the image file. Returns: bool: True if the image is readable, False otherwise. """ try: with Image.open(file_path) as img: img.verify() return True except Exception: return Falsedef delete_unreadable_images(folder_path): """ Delete unreadable image files within a folder.
codeArgs: folder_path (str): Path to the folder to scan. """ supported_formats = ('.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp') deleted_files = 0 for root, _, files in os.walk(folder_path): for file in files: if file.lower().endswith(supported_formats): file_path = os.path.join(root, file) if not is_image_readable(file_path): try: os.remove(file_path) logging.info(f"Deleted unreadable image: {file_path}") deleted_files += 1 except Exception as e: logging.error(f"Error deleting {file_path}: {e}") logging.info(f"Total unreadable image files deleted: {deleted_files}") - Assistant