From 7de12f7d4b14acba6d989360eaef9b75efc9d571 Mon Sep 17 00:00:00 2001 From: Jingtao Xu Date: Mon, 1 Jan 2018 10:34:38 +0800 Subject: [PATCH] add support to modify fields of exist note. --- AnkiConnect.py | 15 +++++++++++++++ README.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index 436c771..56465d4 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -424,6 +424,18 @@ class AnkiBridge: if not note.dupeOrEmpty(): return note + def updateNoteFields(self, params): + collection = self.collection() + if collection is None: + return + + note = collection.getNote(params['id']) + if note is None: + raise Exception("Failed to get note:{}".format(params['id'])) + for name, value in params['fields'].items(): + if name in note: + note[name] = value + note.flush() def addTags(self, notes, tags, add=True): self.startEditing() @@ -1023,6 +1035,9 @@ class AnkiConnect: return results + @webApi() + def updateNoteFields(self, note): + return self.anki.updateNoteFields(note) @webApi() def canAddNotes(self, notes): diff --git a/README.md b/README.md index 900b6b0..6e1c676 100644 --- a/README.md +++ b/README.md @@ -763,6 +763,38 @@ guarantee that your application continues to function properly in the future. } ``` +#### Note Modification #### + +* **updateNoteFields** + + Modify the fields of an exist note. + + *Sample request*: + ```json + { + "action": "updateNoteFields", + "version": 5, + "params": { + "note": { + "id": 1514547547030, + "fields": { + "Front": "new front content", + "Back": "new back content" + }, + } + } + } + ``` + + *Sample result*: + ```json + { + "result": null, + "error": null + } + ``` + + #### Note Tags #### * **addTags**