Rename project to Saiki and unify CLI
This commit is contained in:
19
saiki/ankiconnect.py
Normal file
19
saiki/ankiconnect.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""Small AnkiConnect client."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def anki_request(action: str, url: str = "http://localhost:8765", **params):
|
||||
resp = requests.post(
|
||||
url,
|
||||
json={"action": action, "version": 6, "params": params},
|
||||
timeout=30,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
if data.get("error") is not None:
|
||||
raise RuntimeError(f"AnkiConnect error for {action}: {data['error']}")
|
||||
return data["result"]
|
||||
|
||||
Reference in New Issue
Block a user