import requests
from config import WP_URL, WP_USERNAME, WP_APP_PASSWORD

def delete_automotive():
    auth = (WP_USERNAME, WP_APP_PASSWORD)
    categories_url = f"{WP_URL.rstrip('/')}/wp-json/wp/v2/categories"
    
    # 1. Get the category ID for slug 'automotive'
    resp = requests.get(categories_url, params={"slug": "automotive"}, auth=auth, timeout=15)
    if resp.status_code == 200 and resp.json():
        cat_id = resp.json()[0]["id"]
        print(f"Found category 'automotive' with ID: {cat_id}")
        
        # 2. Delete the category
        delete_url = f"{categories_url}/{cat_id}"
        del_resp = requests.delete(delete_url, params={"force": "true"}, auth=auth, timeout=15)
        if del_resp.status_code == 200:
            print("Successfully deleted 'automotive' category.")
        else:
            print(f"Failed to delete category: {del_resp.status_code} - {del_resp.text}")
    else:
        print("Category 'automotive' not found or already deleted.")

if __name__ == "__main__":
    delete_automotive()
