30 lines
921 B
Python
30 lines
921 B
Python
import requests
|
|
|
|
BASE_URL = "https://stultus.chipperfluff.at"
|
|
|
|
class StultusUnavailable(Exception):
|
|
pass
|
|
|
|
def _get(path: str, params: dict | list = None) -> any:
|
|
try:
|
|
r = requests.get(f"{BASE_URL}/{path}", params=params, timeout=5)
|
|
r.raise_for_status()
|
|
return r.json().get("result")
|
|
except Exception as e:
|
|
raise StultusUnavailable(f"[STULTUS] Failed GET {path}: {e}")
|
|
|
|
def _post(path: str, json: dict = None) -> any:
|
|
try:
|
|
r = requests.post(f"{BASE_URL}/{path}", json=json, timeout=5)
|
|
r.raise_for_status()
|
|
return r.json().get("result") or r.json()
|
|
except Exception as e:
|
|
raise StultusUnavailable(f"[STULTUS] Failed POST {path}: {e}")
|
|
|
|
def ping() -> bool:
|
|
try:
|
|
r = requests.get(f"{BASE_URL}/ping", timeout=2)
|
|
return r.status_code == 200 and r.json().get("status") == "ok"
|
|
except Exception:
|
|
return False
|
|
|