import urllib.request
import json
import time

print('Triggering deep inspect...')
try:
    urllib.request.urlopen("http://127.0.0.1:34332/deep-inspect-trigger?t=" + str(time.time())).read()
except Exception as e:
    pass

print('Waiting for deep inspect result...')
try:
    req = urllib.request.Request("http://127.0.0.1:34332/deep-inspect")
    with urllib.request.urlopen(req, timeout=15) as response:
        result = json.loads(response.read().decode())
        print(f"Got result: {len(result.get('nodes', []))} nodes")
        for node in result.get('nodes', []):
            print(f"Node: {node.get('url')} - {len(node.get('buttons', []))} buttons")
except Exception as e:
    print(f"Error: {e}")
