Add complete Nike football data platform with: - FastMCP server exposing football data tools over HTTP - RapidAPI client for free-api-live-football-data integration - Bootstrap web dashboard with live match/standings views - REST API endpoints for dashboard consumption - Docker support with multi-stage build - Comprehensive README with architecture docs - Minimal .gitignore replacing verbose Python template
108 lines
3.1 KiB
Python
108 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Smoke test for the RapidAPI (free-api-live-football-data) backend.
|
|
|
|
Verifies connectivity, finds MLS, fetches standings and TFC squad.
|
|
Run: python scripts/test_rapidapi.py
|
|
"""
|
|
import sys
|
|
import json
|
|
from pathlib import Path
|
|
|
|
# Ensure project root is on the path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from nike import config
|
|
from nike import rapidapi as rapi
|
|
|
|
|
|
def _pp(label: str, data) -> None:
|
|
"""Pretty-print a section."""
|
|
print(f"\n{'='*60}")
|
|
print(f" {label}")
|
|
print(f"{'='*60}")
|
|
print(json.dumps(data, indent=2, default=str)[:3000]) # trim for readability
|
|
|
|
|
|
def main():
|
|
if not config.RAPIDAPI_KEY:
|
|
print("ERROR: RAPIDAPI_KEY is not set in .env")
|
|
sys.exit(1)
|
|
|
|
print(f"RapidAPI key: {config.RAPIDAPI_KEY[:8]}...{config.RAPIDAPI_KEY[-4:]}")
|
|
print(f"Base URL: {config.RAPIDAPI_BASE}")
|
|
|
|
# 1. Connectivity
|
|
print("\n1) Checking connectivity...")
|
|
status = rapi.check_connection()
|
|
print(f" Connected: {status['connected']}")
|
|
if not status["connected"]:
|
|
print(f" Error: {status.get('error')}")
|
|
sys.exit(1)
|
|
print(f" Latency: {status['latency_ms']} ms")
|
|
|
|
# 2. Search for MLS
|
|
print("\n2) Searching for 'MLS'...")
|
|
mls_data = rapi.search_leagues("MLS")
|
|
_pp("MLS search results", mls_data)
|
|
|
|
# Try to extract league ID
|
|
mls_id = None
|
|
resp = mls_data.get("response") if isinstance(mls_data, dict) else None
|
|
if isinstance(resp, list):
|
|
for item in resp:
|
|
if isinstance(item, dict):
|
|
mls_id = item.get("id") or item.get("primaryId")
|
|
if mls_id:
|
|
mls_id = int(mls_id)
|
|
break
|
|
print(f"\n MLS League ID: {mls_id}")
|
|
|
|
# 3. Standings
|
|
if mls_id:
|
|
print("\n3) Fetching MLS standings...")
|
|
standings = rapi.get_standings(mls_id)
|
|
_pp("MLS Standings", standings)
|
|
|
|
# 4. Search for Toronto FC
|
|
print("\n4) Searching for 'Toronto FC'...")
|
|
tfc_data = rapi.search_teams("Toronto FC")
|
|
_pp("TFC search results", tfc_data)
|
|
|
|
tfc_id = None
|
|
resp = tfc_data.get("response") if isinstance(tfc_data, dict) else None
|
|
if isinstance(resp, list):
|
|
for item in resp:
|
|
if isinstance(item, dict):
|
|
tfc_id = item.get("id") or item.get("primaryId")
|
|
if tfc_id:
|
|
tfc_id = int(tfc_id)
|
|
break
|
|
print(f"\n TFC Team ID: {tfc_id}")
|
|
|
|
# 5. Squad
|
|
if tfc_id:
|
|
print("\n5) Fetching TFC squad...")
|
|
squad = rapi.get_squad(tfc_id)
|
|
_pp("TFC Squad", squad)
|
|
|
|
# 6. Live matches (just check it works)
|
|
print("\n6) Checking live matches endpoint...")
|
|
live = rapi.get_live_matches()
|
|
resp = live.get("response") if isinstance(live, dict) else None
|
|
count = len(resp) if isinstance(resp, list) else 0
|
|
print(f" Live matches right now: {count}")
|
|
|
|
# 7. Trending news
|
|
print("\n7) Fetching trending news...")
|
|
news_data = rapi.get_trending_news()
|
|
_pp("Trending News", news_data)
|
|
|
|
print("\n" + "="*60)
|
|
print(" ALL CHECKS PASSED")
|
|
print("="*60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|