mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
make the backend available over HTTP
This commit is contained in:
parent
99141d9dfb
commit
ac205eeb37
2 changed files with 22 additions and 0 deletions
3
react/Makefile
Normal file
3
react/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
pybackend_run:
|
||||
pip install bottle
|
||||
python pybackend.py
|
19
react/pybackend.py
Normal file
19
react/pybackend.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue