import os import requests BASE_URL = os.getenv("CLICKTHROUGH_URL", "http://127.0.0.1:8123") TOKEN = os.getenv("CLICKTHROUGH_TOKEN", "") SCREEN = int(os.getenv("CLICKTHROUGH_SCREEN", "0")) headers = {} if TOKEN: headers["x-clickthrough-token"] = TOKEN def main(): health = requests.get(f"{BASE_URL}/health", headers=headers, timeout=10) health.raise_for_status() print("health:", health.json()["data"]) see = requests.post( f"{BASE_URL}/see", headers=headers, json={ "screen": SCREEN, "with_grid": True, "grid_rows": 12, "grid_cols": 12, "image_format": "jpeg", "jpeg_quality": 70, }, timeout=30, ) see.raise_for_status() payload = see.json()["data"] print("region:", payload["meta"]["region"]) print("grid:", payload["meta"].get("grid", {})) see_ocr = requests.post( f"{BASE_URL}/see", headers=headers, json={"screen": SCREEN, "ocr": True, "with_grid": False, "ocr_min_confidence": 40}, timeout=30, ) see_ocr.raise_for_status() ocr_items = see_ocr.json()["data"]["meta"].get("ocr", []) print("ocr_items:", len(ocr_items)) if ocr_items: label = ocr_items[0]["text"] click_text = requests.post( f"{BASE_URL}/interact", headers=headers, json={ "screen": SCREEN, "action": {"action": "click_text", "click_text": {"text": label, "match": "exact", "occurrence": "first"}}, }, timeout=30, ) click_text.raise_for_status() click_data = click_text.json()["data"] target = click_data["resolved_target"] verify = requests.post( f"{BASE_URL}/interact/verify", headers=headers, json={ "action": {"screen": SCREEN, "action": {"action": "click", "target": {"mode": "pixel", "x": target["x"], "y": target["y"]}}}, "verify": { "type": "ocr_text_near_point", "text": label, "x": target["x"], "y": target["y"], "radius": 150, "screen": SCREEN, }, "timeout_ms": 1500, }, timeout=30, ) verify.raise_for_status() print("verify:", verify.json()["data"]["verified"]) if __name__ == "__main__": main()