#!/usr/bin/env python3
"""Check all EveryBe posts for featured image status."""
import requests

WP_URL = "https://www.everybeofficial.com/wp-json/wp/v2"
USER = "bambangbot"
APP_PW = "q26r RePo BVy6 pwU2 F3z7 ouyl"

# Get all posts
r = requests.get(f"{WP_URL}/posts?per_page=100", auth=(USER, APP_PW))
posts = r.json()

for p in posts:
    fm_id = p.get('featured_media', 0)
    title = p['title']['rendered'][:60]
    
    # Get media details
    if fm_id:
        mr = requests.get(f"{WP_URL}/media/{fm_id}", auth=(USER, APP_PW))
        if mr.ok:
            m = mr.json()
            url = m.get('source_url', 'N/A')
            mime = m.get('mime_type', 'N/A')
            w = m.get('media_details', {}).get('width', '?')
            h = m.get('media_details', {}).get('height', '?')
            print(f"ID:{p['id']} | {title}")
            print(f"   FM:{fm_id} | {w}x{h} | {mime}")
            print(f"   URL:{url}")
        else:
            print(f"ID:{p['id']} | {title} | FM:{fm_id} (fetch failed)")
    else:
        print(f"ID:{p['id']} | {title} | NO featured media!")
    print()
