Merge pull request #24 from techdavid/aresuspended-and-aredue
Add areDue function and change isSuspended to areSuspended
This commit is contained in:
commit
e50f2af06b
@ -24,6 +24,7 @@ import os.path
|
||||
import select
|
||||
import socket
|
||||
import sys
|
||||
from time import time
|
||||
|
||||
|
||||
#
|
||||
@ -401,18 +402,47 @@ class AnkiBridge:
|
||||
return False
|
||||
|
||||
|
||||
def isSuspended(self, card):
|
||||
def areSuspended(self, cards):
|
||||
suspended = []
|
||||
for card in cards:
|
||||
card = self.collection().getCard(card)
|
||||
if card.queue == -1:
|
||||
return True
|
||||
suspended.append(True)
|
||||
else:
|
||||
return False
|
||||
suspended.append(False)
|
||||
return suspended
|
||||
|
||||
|
||||
def areDue(self, cards):
|
||||
due = []
|
||||
for card in cards:
|
||||
if self.findCards('cid:%s is:new' % card):
|
||||
due.append(True)
|
||||
continue
|
||||
|
||||
date, ivl = self.collection().db.all('select id/1000.0, ivl from revlog where cid = ?', card)[-1]
|
||||
if (ivl >= -1200):
|
||||
if self.findCards('cid:%s is:due' % card):
|
||||
due.append(True)
|
||||
else:
|
||||
due.append(False)
|
||||
else:
|
||||
if date - ivl <= time():
|
||||
due.append(True)
|
||||
else:
|
||||
due.append(False)
|
||||
|
||||
return due
|
||||
|
||||
|
||||
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 self.findCards('cid:%s is:new' % card):
|
||||
intervals.append(0)
|
||||
continue
|
||||
|
||||
interval = self.collection().db.list('select ivl from revlog where cid = ?', card)
|
||||
if not complete:
|
||||
interval = interval[-1]
|
||||
intervals.append(interval)
|
||||
@ -510,22 +540,22 @@ class AnkiBridge:
|
||||
def changeDeck(self, cards, deck):
|
||||
self.startEditing()
|
||||
|
||||
did = self.window().col.decks.id(deck)
|
||||
did = self.collection().decks.id(deck)
|
||||
mod = anki.utils.intTime()
|
||||
usn = self.window().col.usn()
|
||||
usn = self.collection().usn()
|
||||
|
||||
# normal cards
|
||||
scids = anki.utils.ids2str(cards)
|
||||
# remove any cards from filtered deck first
|
||||
self.window().col.sched.remFromDyn(cards)
|
||||
self.collection().sched.remFromDyn(cards)
|
||||
|
||||
# then move into new deck
|
||||
self.window().col.db.execute('update cards set usn=?, mod=?, did=? where id in ' + scids, usn, mod, did)
|
||||
self.collection().db.execute('update cards set usn=?, mod=?, did=? where id in ' + scids, usn, mod, did)
|
||||
self.stopEditing()
|
||||
|
||||
|
||||
def cardsToNotes(self, cards):
|
||||
return self.window().col.db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards))
|
||||
return self.collection().db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards))
|
||||
|
||||
|
||||
def guiBrowse(self, query=None):
|
||||
@ -755,8 +785,13 @@ class AnkiConnect:
|
||||
|
||||
|
||||
@webApi
|
||||
def isSuspended(self, card):
|
||||
return self.anki.isSuspended(card)
|
||||
def areSuspended(self, cards):
|
||||
return self.anki.areSuspended(cards)
|
||||
|
||||
|
||||
@webApi
|
||||
def areDue(self, cards):
|
||||
return self.anki.areDue(cards)
|
||||
|
||||
|
||||
@webApi
|
||||
|
31
README.md
31
README.md
@ -385,23 +385,44 @@ Below is a list of currently supported actions. Requests with invalid actions or
|
||||
true
|
||||
```
|
||||
|
||||
* **isSuspended**
|
||||
* **areSuspended**
|
||||
|
||||
Returns `true` if the given card is suspended or `false` otherwise.
|
||||
Returns an array indicating whether each of the given cards is suspended (in the same order).
|
||||
|
||||
*Sample request*:
|
||||
```
|
||||
{
|
||||
"action": "isSuspended",
|
||||
"action": "areSuspended",
|
||||
"params": {
|
||||
"card": 1483959291685
|
||||
"cards": [1483959291685, 1483959293217]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*Sample response*:
|
||||
```
|
||||
false
|
||||
[false, true]
|
||||
```
|
||||
|
||||
* **areDue**
|
||||
|
||||
Returns an array indicating whether each of the given cards is due (in the same order). Note: cards in the learning
|
||||
queue with a large interval (over 20 minutes) are treated as not due until the time of their interval has passed, to
|
||||
match the way Anki treats them when reviewing.
|
||||
|
||||
*Sample request*:
|
||||
```
|
||||
{
|
||||
"action": "areDue",
|
||||
"params": {
|
||||
"cards": [1483959291685, 1483959293217]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*Sample response*:
|
||||
```
|
||||
[false, true]
|
||||
```
|
||||
|
||||
* **getIntervals**
|
||||
|
Loading…
Reference in New Issue
Block a user