This commit is contained in:
Alex Yatskov 2020-01-05 16:24:20 -08:00
parent 173e43700b
commit 98566ca8ba
8 changed files with 24 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.pyc
AnkiConnect.zip
meta.json

2
package.sh Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/bash
7za a AnkiConnect.zip plugin/*

View File

@ -29,6 +29,7 @@ from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QMessageBox
import anki
import anki.lang
import aqt
from AnkiConnect import web, util
@ -65,6 +66,7 @@ class AnkiConnect:
self.log.write('[{}]\n'.format(name))
json.dump(data, self.log, indent=4, sort_keys=True)
self.log.write('\n\n')
self.log.flush()
def advance(self):
@ -77,10 +79,15 @@ class AnkiConnect:
name = request.get('action', '')
version = request.get('version', 4)
params = request.get('params', {})
key = request.get('key')
reply = {'result': None, 'error': None}
try:
if key != util.setting('apiKey'):
raise Exception('valid api key must be provided')
method = None
for methodName, methodInst in inspect.getmembers(self, predicate=inspect.ismethod):
apiVersionLast = 0
apiNameLast = None
@ -580,11 +587,11 @@ class AnkiConnect:
mm = collection.models
# Generate new Note
m = mm.new(_(modelName))
m = mm.new(anki.lang._(modelName))
# Create fields and add them to Note
for field in inOrderFields:
fm = mm.newField(_(field))
fm = mm.newField(anki.lang._(field))
mm.addField(m, fm)
# Add shared css to model if exists. Use default otherwise
@ -594,7 +601,7 @@ class AnkiConnect:
# Generate new card template(s)
cardCount = 1
for card in cardTemplates:
t = mm.newTemplate(_('Card ' + str(cardCount)))
t = mm.newTemplate(anki.lang._('Card ' + str(cardCount)))
cardCount += 1
t['qfmt'] = card['Front']
t['afmt'] = card['Back']

View File

@ -1,2 +1,11 @@
{
"apiKey": null,
"apiLogPath": null,
"apiPollInterval": 25,
"apiVersion": 6,
"webBacklog": 5,
"webBindAddress": "127.0.0.1",
"webBindPort": 8765,
"webCorsOrigin": "http://localhost",
"webTimeout": 10000
}

View File

@ -0,0 +1 @@
Read the documentation on the [AnkiConnect](https://foosoft.net/projects/anki-connect/) project page for details.

View File

@ -1,3 +1,2 @@
#!/usr/bin/sh
#!/usr/bin/bash
python -m unittest discover -v tests

View File

@ -9,9 +9,6 @@ class TestMisc(unittest.TestCase):
# version
self.assertEqual(util.invoke('version'), 6)
# upgrade
util.invoke('upgrade')
# sync
util.invoke('sync')

5
zip.sh
View File

@ -1,5 +0,0 @@
#!/usr/bin/bash
rm AnkiConnect.zip
cp AnkiConnect.py __init__.py
7za a AnkiConnect.zip __init__.py
rm __init__.py