Merge pull request #22 from techdavid/getintervals-and-cardstonotes

Create getIntervals and cardsToNotes functions
This commit is contained in:
Alex Yatskov 2017-08-09 17:05:13 -07:00 committed by GitHub
commit caea9cbc08
2 changed files with 88 additions and 1 deletions

View File

@ -409,6 +409,16 @@ class AnkiBridge:
return False 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): def startEditing(self):
self.window().requireReset() self.window().requireReset()
@ -497,6 +507,10 @@ class AnkiBridge:
return [] 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): def guiBrowse(self, query=None):
browser = aqt.dialogs.open('Browser', self.window()) browser = aqt.dialogs.open('Browser', self.window())
browser.activateWindow() browser.activateWindow()
@ -728,6 +742,11 @@ class AnkiConnect:
return self.anki.isSuspended(card) return self.anki.isSuspended(card)
@webApi
def getIntervals(self, cards, complete=False):
return self.anki.getIntervals(cards, complete)
@webApi @webApi
def upgrade(self): def upgrade(self):
response = QMessageBox.question( response = QMessageBox.question(
@ -766,6 +785,11 @@ class AnkiConnect:
return self.anki.findCards(query) return self.anki.findCards(query)
@webApi
def cardsToNotes(self, cards):
return self.anki.cardsToNotes(cards)
@webApi @webApi
def guiBrowse(self, query=None): def guiBrowse(self, query=None):
return self.anki.guiBrowse(query) return self.anki.guiBrowse(query)

View File

@ -404,6 +404,46 @@ Below is a list of currently supported actions. Requests with invalid actions or
false 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** * **findNotes**
Returns an array of note IDs for a given query (same query syntax as **guiBrowse**). Returns an array of note IDs for a given query (same query syntax as **guiBrowse**).
@ -411,7 +451,7 @@ Below is a list of currently supported actions. Requests with invalid actions or
*Sample request*: *Sample request*:
``` ```
{ {
"action": "findCards", "action": "findNotes",
"params": { "params": {
"query": "deck:current" "query": "deck:current"
} }
@ -450,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** * **guiBrowse**
Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found. Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found.