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**).