import asyncio import httpx import time import sys import os # Set encoding for Windows CLI if sys.platform == "win32": import codecs sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) async def test_system(): print("\n" + "="*50) print("šŸ” MEIH SYSTEM HEALTH CHECK") print("="*50 + "\n") async with httpx.AsyncClient(timeout=30.0) as client: # 1. Test FlareSolverr print("šŸ“” Checking FlareSolverr...") try: resp = await client.get("http://localhost:8191/health") if resp.status_code == 200: print("āœ… FlareSolverr: ONLINE") else: print(f"āŒ FlareSolverr: ERROR (Status {resp.status_code})") except Exception as e: print(f"āŒ FlareSolverr: OFFLINE ({e})") # 2. Test FastAPI Backend print("\nāš™ļø Checking FastAPI Backend...") try: resp = await client.get("http://localhost:8000/") if resp.status_code == 200: print("āœ… Backend: ONLINE") data = resp.json() print(f" Mirror Active: {data.get('active_mirror')}") print(f" Engine Status: {data.get('engine_status')}") else: print(f"āŒ Backend: ERROR (Status {resp.status_code})") except Exception as e: print(f"āŒ Backend: OFFLINE ({e})") # 3. Test Scrapper (Latest Movies) print("\nšŸŽ¬ Testing Movie Scrapper (Live Fetch)...") try: start_time = time.time() resp = await client.get("http://localhost:8000/latest") duration = time.time() - start_time if resp.status_code == 200: items = resp.json() print(f"āœ… Scrapper: SUCCESS") print(f" Items Found: {len(items)}") print(f" Time Taken: {duration:.2f}s") if items: print(f" Top Item: {items[0]['title']}") else: print(f"āŒ Scrapper: FAILED (Status {resp.status_code})") except Exception as e: print(f"āŒ Scrapper: ERROR ({e})") # 4. Test Category (Fast Path) print("\nšŸ“‚ Testing Category (Prefetch Integrity)...") try: start_time = time.time() resp = await client.get("http://localhost:8000/category/arabic-movies") duration = time.time() - start_time if resp.status_code == 200: items = resp.json() print(f"āœ… Category Path: STABLE") print(f" Items: {len(items)}") print(f" Time Taken: {duration:.2f}s (Should be < 0.5s if cached)") else: print(f"āŒ Category: FAILED") except Exception as e: print(f"āŒ Category: ERROR ({e})") print("\n" + "="*50) print("✨ ALL TESTS COMPLETED") print("="*50 + "\n") if __name__ == "__main__": asyncio.run(test_system())