1

Expanding API

This commit is contained in:
Alex Yatskov 2016-05-02 16:30:03 -07:00
parent d2bdda937a
commit 60f85a962c

View File

@ -35,6 +35,7 @@ class AnkiConnect:
self.handlers = { self.handlers = {
'addNote': self.apiAddNote, 'addNote': self.apiAddNote,
'apiCanAddNote': self.apiCanAddNote, 'apiCanAddNote': self.apiCanAddNote,
'apiCanAddNotes': self.apiCanAddNotes,
'getVersion': self.apiGetVersion, 'getVersion': self.apiGetVersion,
} }
@ -105,6 +106,22 @@ class AnkiConnect:
return self.anki.canAddNote(params['deck'], params['model'], params['fields']) return self.anki.canAddNote(params['deck'], params['model'], params['fields'])
def apiCanAddNotes(self, data):
definitions = data.get('definitions', [])
for definition in definitions:
definitions['anki'] = results = {}
for mode in ['vocabExp', 'vocabReading', 'kanji']:
params = self.prepareNoteParams(definition, mode)
results[mode] = params is not None and self.anki.canAddNote(
params['deck'],
params['model'],
params['fields']
)
return definitions
def apiGetVersion(self, data): def apiGetVersion(self, data):
return {'version': constants.c['appVersion']} return {'version': constants.c['appVersion']}