From 30f3d5618a6347948b21b629e06537b43aa121d2 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 3 Aug 2017 22:31:47 +0100 Subject: [PATCH] Rename browse to findCards and add new findNotes function --- AnkiConnect.py | 34 +++++++++++++++++++++++----------- README.md | 35 +++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/AnkiConnect.py b/AnkiConnect.py index a09006e..f1e0aec 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -460,6 +460,20 @@ class AnkiBridge: return deck['name'] + def findNotes(self, query=None): + if query is not None: + return aqt.mw.col.findNotes(query) + else: + return [] + + + def findCards(self, query=None): + if query is not None: + return aqt.mw.col.findCards(query) + else: + return [] + + def guiBrowse(self, query=None): browser = aqt.dialogs.open('Browser', self.window()) browser.activateWindow() @@ -474,13 +488,6 @@ class AnkiBridge: return browser.model.cards - def browse(self, query=None): - if query is not None: - return aqt.mw.col.findCards(query) - else: - return [] - - def guiAddCards(self): addCards = aqt.dialogs.open('AddCards', self.window()) addCards.activateWindow() @@ -722,13 +729,18 @@ class AnkiConnect: @webApi - def guiBrowse(self, query=None): - return self.anki.guiBrowse(query) + def findNotes(self, query=None): + return self.anki.findNotes(query) @webApi - def browse(self, query=None): - return self.anki.browse(query) + def findCards(self, query=None): + return self.anki.findCards(query) + + + @webApi + def guiBrowse(self, query=None): + return self.anki.guiBrowse(query) @webApi diff --git a/README.md b/README.md index cc003ba..980f4fe 100644 --- a/README.md +++ b/README.md @@ -383,14 +383,37 @@ Below is a list of currently supported actions. Requests with invalid actions or null ``` -* **guiBrowse** +* **findNotes** - Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found. + Returns an array of note IDs for a given query (same query syntax as **guiBrowse**). *Sample request*: ``` { - "action": "guiBrowse", + "action": "findCards", + "params": { + "query": "deck:current" + } + } + ``` + + *Sample response*: + ``` + [ + 1483959289817, + 1483959291695 + ] + ``` + +* **findCards** + + Returns an array of card IDs for a given query (functionally identical to **guiBrowse** but doesn't use the GUI + for better performance). + + *Sample request*: + ``` + { + "action": "findCards", "params": { "query": "deck:current" } @@ -406,14 +429,14 @@ Below is a list of currently supported actions. Requests with invalid actions or ] ``` -* **browse** +* **guiBrowse** - Functionally identical to **guiBrowse**, but accesses the database without using the GUI for increased performance. + Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found. *Sample request*: ``` { - "action": "browse", + "action": "guiBrowse", "params": { "query": "deck:current" }