#!/usr/bin/env python3
"""
Simple test script to run the trending job locally.
"""

import os
import sys
from pathlib import Path

# Load environment variables from .env file
from dotenv import load_dotenv
load_dotenv()

# Add the src directory to Python path
sys.path.insert(0, str(Path(__file__).parent / "src"))

from dagster import build_asset_context
from src.assets.trending.trending_now_clips import trending_clip_asset

def test_trending_job():
    """Test the trending job with the fixed GroupBy syntax."""
    print("Testing trending job with fixed GroupBy syntax...")
    
    # Create context
    context = build_asset_context()
    
    try:
        print("Executing trending_now_clips asset...")
        result = trending_clip_asset(context)
        print(f"✅ Job completed successfully!")
        print(f"Result shape: {result.shape}")
        print(f"Result columns: {result.columns.tolist()}")
        
        # Check if CLIP_IDS are populated
        non_empty_clips = result[result['CLIP_IDS'].apply(lambda x: len(x) > 0)]
        print(f"Languages with clips: {len(non_empty_clips)}")
        if len(non_empty_clips) > 0:
            print("Sample languages with clips:")
            for _, row in non_empty_clips.head(3).iterrows():
                print(f"  {row['LANGUAGE']}: {len(row['CLIP_IDS'])} clips")
        else:
            print("⚠️  No languages have clips (CLIP_IDS are empty)")
            
    except Exception as e:
        print(f"❌ Error running trending job: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    test_trending_job() 