import pandas as pd
import os

# Load the Excel file
# data = pd.read_excel("/home/karthikeyan-c/Documents/image_path_list.xlsx")
data = pd.read_excel("/fileserver/seller/image_path_list.xlsx")

def delete_images(image_url):
    if pd.isna(image_url):
        print(f"Skipping empty image URL.")
        return

    try:
        # Extract the path after the domain (skip the first 3 segments)
        remaining_part = '/'.join(image_url.split('/')[3:])
        base_path = "/fileserver"
        image_path_full = os.path.join(base_path, remaining_part)

        if os.path.exists(image_path_full):
            os.remove(image_path_full)
            print(f"Deleted: {image_url}")
        else:
            print(f"File not found: {image_url}")
    except Exception as e:
        print(f"Error processing {image_url}: {e}")

# Loop through all image paths
for path in data["Itma_url"].dropna().unique():
    delete_images(path)
