📋 Lưu ý vận hành
- Tool phải mở — thoát app thì API tắt.
- Chỉ localhost — script trên máy khác không gọi được (trừ khi tự forward port, không khuyến nghị).
- Đổi port — cập nhật URL trong script tích hợp.
- Kịch bản tại
data/scripts/*.apc— tạo/import qua UI trước khi gọi API. - Một lúc chỉ chạy một kịch bản qua engine.
Ví dụ: start → chờ xong → dừng
Kịch bản NhiemVuNgay có biến taikhoan ở Node Start — xem Khai báo biến tùy chỉnh.
import time
import requests
BASE = "http://127.0.0.1:8765/api/v1"
NAME = "NhiemVuNgay"
def api(method, path, **kw):
r = requests.request(method, BASE + path, timeout=8, **kw)
r.raise_for_status()
return r.json()
# App đang mở?
h = api("GET", "/health")
assert h.get("ok")
# Đúng tên .apc
names = [s["name"] for s in api("GET", "/scripts")["scripts"]]
assert NAME in names
# Dừng nếu engine bận
if api("GET", f"/scripts/{NAME}/status")["engine"]["running"]:
api("POST", "/run/stop")
time.sleep(1)
# Start kèm biến
api("POST", f"/scripts/{NAME}/start", json={"variables": {"taikhoan": "acc01"}})
# Chờ kết thúc
for _ in range(600):
st = api("GET", f"/scripts/{NAME}/status")
if not st["engine"]["running"]:
print("xong")
break
time.sleep(1)
else:
api("POST", "/run/stop")