From 1a2c559ca20a7c844b340bf6b53a43c55db70e83 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 9 Aug 2017 18:40:09 +0100 Subject: [PATCH 1/3] Add getIntervals function --- AnkiConnect.py | 15 +++++++++++++++ README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index 36d2f7c..42e9367 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -409,6 +409,16 @@ class AnkiBridge: return False + def getIntervals(self, cards, complete=False): + intervals = [] + for card in cards: + interval = self.window().col.db.list('select ivl from revlog where cid = ?', card) + if not complete: + interval = interval[-1] + intervals.append(interval) + return intervals + + def startEditing(self): self.window().requireReset() @@ -728,6 +738,11 @@ class AnkiConnect: return self.anki.isSuspended(card) + @webApi + def getIntervals(self, cards, complete=False): + return self.anki.getIntervals(cards, complete) + + @webApi def upgrade(self): response = QMessageBox.question( diff --git a/README.md b/README.md index b3ec799..04a35fb 100644 --- a/README.md +++ b/README.md @@ -404,6 +404,46 @@ Below is a list of currently supported actions. Requests with invalid actions or false ``` +* **getIntervals** + + Returns an array of the most recent intervals for each given card ID, or a 2-dimensional array of all the intervals + for each given card ID when `complete` is `true`. (Negative intervals are in seconds and positive intervals in days.) + + *Sample request 1*: + ``` + { + "action": "getIntervals", + "params": { + "cards": [1502298033753, 1502298036657] + } + } + ``` + + *Sample response 1*: + ``` + [-14400, 3] + ``` + + *Sample request 2*: + ``` + { + "action": "getIntervals", + "params": { + "cards": [1502298033753, 1502298036657], + "complete": true + } + } + ``` + + *Sample response 2*: + ``` + [ + [-120, -180, -240, -300, -360, -14400], + [-120, -180, -240, -300, -360, -14400, 1, 3] + ] + ``` + + * **findNotes** Returns an array of note IDs for a given query (same query syntax as **guiBrowse**). From 6a6f9d7d2a10bc5df2420e4f80621d7ae8054797 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 9 Aug 2017 18:55:31 +0100 Subject: [PATCH 2/3] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 04a35fb..bd9858c 100644 --- a/README.md +++ b/README.md @@ -451,7 +451,7 @@ Below is a list of currently supported actions. Requests with invalid actions or *Sample request*: ``` { - "action": "findCards", + "action": "findNotes", "params": { "query": "deck:current" } From e02f8b2d65898ef56be8d28ee5f40ceea7fa4090 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 9 Aug 2017 19:05:00 +0100 Subject: [PATCH 3/3] Add cardsToNotes function --- AnkiConnect.py | 9 +++++++++ README.md | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) 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.