| |
| import subprocess |
| import json |
| import sys |
| import time |
|
|
| def run_command(cmd): |
| try: |
| result = subprocess.run( |
| cmd, |
| shell=True, |
| capture_output=True, |
| text=True, |
| check=True, |
| timeout=10 |
| ) |
| return result.stdout.strip() |
| except subprocess.CalledProcessError as e: |
| |
| return None |
| except subprocess.TimeoutExpired: |
| print("--- [Pending] 命令执行超时 ---") |
| return None |
|
|
| def main(): |
| print("--- [Pending]: 检查设备待批准列表...") |
| |
| json_output = run_command("openclaw devices list --json") |
| |
| if not json_output: |
| |
| sys.exit(0) |
|
|
| try: |
| data = json.loads(json_output) |
| except json.JSONDecodeError: |
| |
| sys.exit(0) |
|
|
| pending_list = data.get("pending", []) |
| |
| if not isinstance(pending_list, list): |
| sys.exit(0) |
|
|
| request_ids = [] |
| |
| |
| |
| for item in pending_list: |
| if isinstance(item, dict) and "requestId" in item: |
| request_ids.append(item["requestId"]) |
|
|
| if not request_ids: |
| sys.exit(0) |
|
|
| print(f"--- [Pending] 发现 {len(request_ids)} 个待批准请求 ---") |
| |
| for req_id in request_ids: |
| cmd = f"openclaw devices approve {req_id}" |
| print(f"--- [Pending] 正在批准: {req_id} ---") |
| subprocess.run(cmd, shell=True, capture_output=True, text=True) |
| |
| print("--- [Pending] 所有请求处理完毕 ---") |
|
|
| if __name__ == "__main__": |
| main() |