From e8088146f37d3d2f4290ca7013b56ac6ab0fbf2c Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 3 Aug 2017 21:07:22 +0100 Subject: [PATCH] Add tagging and suspend functions --- AnkiConnect.py | 34 ++++++++++++++++++++++ README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index f323d50..82798a8 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -375,6 +375,20 @@ class AnkiBridge: return note + def addTags(self, query, tags, add=True): + notes = aqt.mw.col.findNotes(query) + aqt.mw.col.tags.bulkAdd(notes, tags, add) + + + def suspend(self, query, suspend=True): + cards = aqt.mw.col.findCards(query) + if suspend: + suspendFunction = aqt.mw.col.sched.suspendCards + else: + suspendFunction = aqt.mw.col.sched.unsuspendCards + suspendFunction(cards) + + def startEditing(self): self.window().requireReset() @@ -662,6 +676,26 @@ class AnkiConnect: return results + @webApi + def addTags(self, query, tags, add=True): + return self.anki.addTags(query, tags, add) + + + @webApi + def removeTags(self, query, tags): + return self.anki.addTags(query, tags, False) + + + @webApi + def suspend(self, query, suspend=True): + return self.anki.suspend(query, suspend) + + + @webApi + def unsuspend(self, query): + return self.anki.suspend(query, False) + + @webApi def upgrade(self): response = QMessageBox.question( diff --git a/README.md b/README.md index a824339..b0ba8f5 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,84 @@ Below is a list of currently supported actions. Requests with invalid actions or ] ``` +* **addTags** + + Adds tags to notes matching a query (same syntax as **browse**/**guiBrowse**). + + *Sample request*: + ``` + { + "action": "addTags", + "params": { + "query": "deck:French or deck:Spanish", + "tags": "european-languages" + } + } + ``` + + *Sample response*: + ``` + null + ``` + +* **removeTags** + + Remove tags from notes matching a query (same syntax as **browse**/**guiBrowse**). + + *Sample request*: + ``` + { + "action": "removeTags", + "params": { + "query": "deck:Japanese or deck:Chinese", + "tags": "european-languages" + } + } + ``` + + *Sample response*: + ``` + null + ``` + +* **suspend** + + Suspend cards matching a query (same syntax as **browse**/**guiBrowse**). + + *Sample request*: + ``` + { + "action": "suspend", + "params": { + "query": "tag:difficult" + } + } + ``` + + *Sample response*: + ``` + null + ``` + +* **unsuspend** + + Unsuspend cards matching a query (same syntax as **browse**/**guiBrowse**). + + *Sample request*: + ``` + { + "action": "unsuspend", + "params": { + "query": "tag:easy" + } + } + ``` + + *Sample response*: + ``` + null + ``` + * **guiBrowse** Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found.