From ac205eeb3716b5e6e110616c1b6d04414dab373e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 6 Jan 2020 12:47:09 +1000 Subject: [PATCH] make the backend available over HTTP --- react/Makefile | 3 +++ react/pybackend.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 react/Makefile create mode 100644 react/pybackend.py diff --git a/react/Makefile b/react/Makefile new file mode 100644 index 000000000..ce9a9c795 --- /dev/null +++ b/react/Makefile @@ -0,0 +1,3 @@ +pybackend_run: + pip install bottle + python pybackend.py diff --git a/react/pybackend.py b/react/pybackend.py new file mode 100644 index 000000000..5169ea71d --- /dev/null +++ b/react/pybackend.py @@ -0,0 +1,19 @@ +from bottle import run, route, request, response +from anki.pybackend import PythonBackend +from anki import Collection +import sys, os + +path = os.path.expanduser("~/test.anki2") +if not os.path.exists(path): + print(f"to use, copy your collection to {path}") + sys.exit(1) + +col = Collection(path) +backend = PythonBackend(col) + +@route('/request', method="POST") +def proto_request(): + response.content_type = 'application/protobuf' + return backend.run_command_bytes(request.body.read()) + +run(host='localhost', port=5006)