From 47f9db35bd58ffa93b077dfea4316d11388a2c70 Mon Sep 17 00:00:00 2001 From: Mikhail Pontus Date: Tue, 26 Feb 2019 20:28:36 +0300 Subject: [PATCH] Introduce note deletion functionality --- AnkiConnect.py | 7 +++++++ README.md | 24 ++++++++++++++++++++++++ tests/test_notes.py | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index 7b7cb81..1222e62 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -1001,6 +1001,13 @@ class AnkiConnect: return result + @api() + def deleteNotes(self, notes): + try: + self.collection().remNotes(notes) + finally: + self.stopEditing() + diff --git a/README.md b/README.md index 66c165b..fac2c27 100644 --- a/README.md +++ b/README.md @@ -1018,6 +1018,30 @@ guarantee that your application continues to function properly in the future. ``` +* **deleteNotes** + + Deletes notes with the given ids. If a note has several cards associated with it, all associated cards will be deleted. + + *Sample request*: + ```json + { + "action": "deleteNotes", + "version": 6, + "params": { + "notes": [1502298033753] + } + } + ``` + + *Sample result*: + ```json + { + "result": null, + "error": null + } + ``` + + #### Cards #### * **suspend** diff --git a/tests/test_notes.py b/tests/test_notes.py index eddac05..b9ac558 100755 --- a/tests/test_notes.py +++ b/tests/test_notes.py @@ -84,6 +84,10 @@ class TestNotes(unittest.TestCase): noteIds = util.invoke('findNotes', query='deck:test') self.assertEqual(len(noteIds), len(notes) + 1) + # deleteNotes + util.invoke('deleteNotes', notes=noteIds) + noteIds = util.invoke('findNotes', query='deck:test') + self.assertEqual(len(noteIds), 0) if __name__ == '__main__': unittest.main()