#!/usr/bin/env python3
"""
Fetch Trello card #910 via the MCP and extract language->docId mapping.
"""
import json
import subprocess
import re
import sys

# The card ID for #910
card_id = "6a1d693138130a39f9fa9167"

# Parse the card description to extract language->docId mapping
# Expected format: "lang: https://docs.google.com/document/d/<docId>/..."
def parse_description(desc):
    """Extract language->docId mapping from Trello card description."""
    langs = {}
    if not desc:
        return langs
    
    # Pattern: "lang: ... /d/<docId>/"
    # Line by line approach to respect the format
    for line in desc.split('\n'):
        # Check if line has docs.google.com
        if 'docs.google.com' not in line:
            continue
        
        # Extract language (token before ':' in lowercase)
        colon_idx = line.find(':')
        if colon_idx > 0:
            lang_part = line[:colon_idx].strip().lower()
            # Sanity check: lang should be a word, not empty
            if not lang_part or len(lang_part) > 10:
                continue
        else:
            continue
        
        # Extract docId from /d/<docId>/ pattern
        match = re.search(r'/d/([^/]+)/', line)
        if match:
            doc_id = match.group(1)
            langs[lang_part] = doc_id
    
    return langs

# Since we can't directly call MCP from Python, let's use the Bash wrapper
# Actually, let me just use curl or fetch the data another way
# Let's try to check if there's a cached response or use an API directly

# For now, let's try to execute a simple Python that reads the description from a file
# Or we can manually call the helper

print(json.dumps({"card_id": card_id}))
