import json
import sys
from db.connection import get_connection

def fetch_result(call_id):
    with get_connection() as conn:
        with conn.cursor() as cur:
            cur.execute("SELECT status, transcript, speaker_count, duration_seconds, error_message FROM stt_jobs WHERE call_id=%s", (call_id,))
            row = cur.fetchone()
            if row:
                print(json.dumps(row, indent=2))
            else:
                print(f"Job with call_id {call_id} not found in database.")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python3 fetch_result.py <call_id>")
    else:
        fetch_result(sys.argv[1])
