Change isSuspended to areSuspended; add areDue function; code style fixes
This commit is contained in:
parent
c09c171dcd
commit
a6c15d7bb2
@ -24,6 +24,7 @@ import os.path
|
|||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -401,18 +402,44 @@ class AnkiBridge:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def isSuspended(self, card):
|
def areSuspended(self, cards):
|
||||||
card = self.collection().getCard(card)
|
suspended = []
|
||||||
if card.queue == -1:
|
for card in cards:
|
||||||
return True
|
card = self.collection().getCard(card)
|
||||||
else:
|
if card.queue == -1:
|
||||||
return False
|
suspended.append(True)
|
||||||
|
else:
|
||||||
|
suspended.append(False)
|
||||||
|
return suspended
|
||||||
|
|
||||||
|
|
||||||
|
def areDue(self, cards):
|
||||||
|
due = []
|
||||||
|
for card in cards:
|
||||||
|
date, ivl = self.collection().db.all('select id/1000.0, ivl from revlog where cid = ?', card)[-1]
|
||||||
|
|
||||||
|
if self.findCards('cid:%s is:new' % card):
|
||||||
|
due.append(True)
|
||||||
|
continue
|
||||||
|
|
||||||
|
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):
|
def getIntervals(self, cards, complete=False):
|
||||||
intervals = []
|
intervals = []
|
||||||
for card in cards:
|
for card in cards:
|
||||||
interval = self.window().col.db.list('select ivl from revlog where cid = ?', card)
|
interval = self.collection().db.list('select ivl from revlog where cid = ?', card)
|
||||||
if not complete:
|
if not complete:
|
||||||
interval = interval[-1]
|
interval = interval[-1]
|
||||||
intervals.append(interval)
|
intervals.append(interval)
|
||||||
@ -510,22 +537,22 @@ class AnkiBridge:
|
|||||||
def changeDeck(self, cards, deck):
|
def changeDeck(self, cards, deck):
|
||||||
self.startEditing()
|
self.startEditing()
|
||||||
|
|
||||||
did = self.window().col.decks.id(deck)
|
did = self.collection().decks.id(deck)
|
||||||
mod = anki.utils.intTime()
|
mod = anki.utils.intTime()
|
||||||
usn = self.window().col.usn()
|
usn = self.collection().usn()
|
||||||
|
|
||||||
# normal cards
|
# normal cards
|
||||||
scids = anki.utils.ids2str(cards)
|
scids = anki.utils.ids2str(cards)
|
||||||
# remove any cards from filtered deck first
|
# remove any cards from filtered deck first
|
||||||
self.window().col.sched.remFromDyn(cards)
|
self.collection().sched.remFromDyn(cards)
|
||||||
|
|
||||||
# then move into new deck
|
# 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()
|
self.stopEditing()
|
||||||
|
|
||||||
|
|
||||||
def cardsToNotes(self, cards):
|
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):
|
def guiBrowse(self, query=None):
|
||||||
@ -755,8 +782,13 @@ class AnkiConnect:
|
|||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def isSuspended(self, card):
|
def areSuspended(self, cards):
|
||||||
return self.anki.isSuspended(card)
|
return self.anki.areSuspended(cards)
|
||||||
|
|
||||||
|
|
||||||
|
@webApi
|
||||||
|
def areDue(self, cards):
|
||||||
|
return self.anki.areDue(cards)
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
|
32
README.md
32
README.md
@ -385,23 +385,45 @@ Below is a list of currently supported actions. Requests with invalid actions or
|
|||||||
true
|
true
|
||||||
```
|
```
|
||||||
|
|
||||||
* **isSuspended**
|
* **areSuspended**
|
||||||
|
|
||||||
Returns `true` if the given card is suspended or `false` otherwise.
|
Returns an array, where the value at an index is `true` if the card with the given ID at that index is suspended, or
|
||||||
|
`false` otherwise.
|
||||||
|
|
||||||
*Sample request*:
|
*Sample request*:
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"action": "isSuspended",
|
"action": "areSuspended",
|
||||||
"params": {
|
"params": {
|
||||||
"card": 1483959291685
|
"cards": [1483959291685, 1483959293217]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
*Sample response*:
|
*Sample response*:
|
||||||
```
|
```
|
||||||
false
|
[false, true]
|
||||||
|
```
|
||||||
|
|
||||||
|
* **areDue**
|
||||||
|
|
||||||
|
Returns an array, where the value at an index is `true` if the card with the ID given at that index is due, or
|
||||||
|
`false` otherwise. 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.
|
||||||
|
|
||||||
|
*Sample request*:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"action": "areDue",
|
||||||
|
"params": {
|
||||||
|
"cards": [1483959291685, 1483959293217]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Sample response*:
|
||||||
|
```
|
||||||
|
[false, true]
|
||||||
```
|
```
|
||||||
|
|
||||||
* **getIntervals**
|
* **getIntervals**
|
||||||
|
Loading…
Reference in New Issue
Block a user