import requests
import json
from config import WP_URL, WP_USERNAME, WP_APP_PASSWORD

def main():
    auth = (WP_USERNAME, WP_APP_PASSWORD)
    url = f"{WP_URL.rstrip('/')}/wp-json/wp/v2/news_category"
    try:
        r = requests.get(url, params={"per_page": 100}, auth=auth, timeout=15)
        if r.status_code == 200:
            categories = r.json()
            print("=== WordPress Categories (news_category) ===")
            for cat in categories:
                print(f"ID: {cat.get('id')} | Slug: {cat.get('slug')} | Name: {cat.get('name')}")
        else:
            print(f"Failed to fetch: {r.status_code} - {r.text}")
    except Exception as e:
        print(f"Error: {e}")

if __name__ == '__main__':
    main()
