Files
AIO_3D_Print_Local_Screen/utils/aio_print_api.py
lhye200 4e6636c509 init
Co-authored-by: Copilot <copilot@github.com>
2026-05-08 22:23:00 +08:00

36 lines
1.0 KiB
Python

import requests
class AIOPrrintSystemAPI:
def __init__(self, api_url="http://127.0.0.1:5001/api/v1", api_key=""):
self.api_url = api_url
self.api_key = api_key
self.headers = {"X-Api-Key": self.api_key}
def _post_action(self, method, **kwargs):
url = f"{self.api_url}/octoprint_client"
payload = {"method": method, "kwargs": kwargs}
try:
r = requests.post(url, json=payload, headers=self.headers, timeout=5)
return r.json()
except:
return None
def print(self, *args, **kwargs):
pass
def get_status(self):
url = f"{self.api_url}/status"
try:
r = requests.get(url, headers=self.headers, timeout=5)
r.raise_for_status()
return r.json()
except:
return {"status": {}, "job": {}}
def pause_print(self):
return self._post_action("pause_print", action="pause")
def stop_print(self):
return self._post_action("cancel_print")