From b8c5b7c980af8bb17de116844e7d0ad74775b3e4 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 16 Aug 2017 22:26:53 +0100 Subject: [PATCH] Add deckNamesAndIds action --- AnkiConnect.py | 16 ++++++++++++++++ README.md | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index c7f478f..d31859c 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -515,6 +515,17 @@ class AnkiBridge: return collection.decks.allNames() + def deckNamesAndIds(self): + decks = {} + + deckNames = self.deckNames() + for deck in deckNames: + id = self.collection().decks.id(deck) + decks[deck] = id + + return decks + + def deckNameFromId(self, deckId): collection = self.collection() if collection is not None: @@ -753,6 +764,11 @@ class AnkiConnect: return self.anki.deckNames() + @webApi + def deckNamesAndIds(self): + return self.anki.deckNamesAndIds() + + @webApi def modelNames(self): return self.anki.modelNames() diff --git a/README.md b/README.md index e16faf1..d2493c3 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,24 @@ Below is a list of currently supported actions. Requests with invalid actions or ] ``` +* **deckNamesAndIds** + + Gets the complete list of deck names and their respective IDs for the current user. + + *Sample request*: + ``` + { + "action": "deckNamesAndIds" + } + ``` + + *Sample response*: + ``` + { + "Default": 1 + } + ``` + * **modelNames** Gets the complete list of model names for the current user.