Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| 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: | |
| # ๅฆๆๆฏ้้ถ้ๅบ็ ๏ผๅฏ่ฝๆฏๆฒกๆ pending ่ฏทๆฑ๏ผ้้ปๅค็ | |
| 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: | |
| # ่พๅบไธๆฏๆๆ็ JSON๏ผๅฟฝ็ฅ | |
| sys.exit(0) | |
| pending_list = data.get("pending", []) | |
| if not isinstance(pending_list, list): | |
| sys.exit(0) | |
| request_ids = [] | |
| # ้ป่พไผๅ๏ผ็ปไธ้ๅ้ป่พ๏ผไธๅ็กฌ็ผ็ ็ดขๅผๅ็๏ผ้ค้ๆฐๆฎ็ปๆ้ๅธธ็นๆฎ | |
| # ๆ นๆฎๅ้ป่พ๏ผไผผไนๆฏไป็ดขๅผ 3 ๅผๅงๆ่ ๆฏๅญๅ ธ็ฑปๅ | |
| 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() |