diff --git a/AnkiConnect.py b/AnkiConnect.py index 42e9367..c6f4897 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -507,6 +507,10 @@ class AnkiBridge: return [] + def cardsToNotes(self, cards): + return self.window().col.db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards)) + + def guiBrowse(self, query=None): browser = aqt.dialogs.open('Browser', self.window()) browser.activateWindow() @@ -781,6 +785,11 @@ class AnkiConnect: return self.anki.findCards(query) + @webApi + def cardsToNotes(self, cards): + return self.anki.cardsToNotes(cards) + + @webApi def guiBrowse(self, query=None): return self.anki.guiBrowse(query) diff --git a/README.md b/README.md index bd9858c..43b9c63 100644 --- a/README.md +++ b/README.md @@ -490,6 +490,29 @@ Below is a list of currently supported actions. Requests with invalid actions or ] ``` +* **cardsToNotes** + + Returns an (unordered) array of note IDs for the given card IDs. For cards with the same note, the ID is only + given once in the array. + + *Sample request*: + ``` + { + "action": "cardsToNotes", + "params": { + "cards": [1502098034045, 1502098034048, 1502298033753] + } + } + ``` + + *Sample response*: + ``` + [ + 1502098029797, + 1502298025183 + ] + ``` + * **guiBrowse** Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found.