Add "forgetCards" and "relearnCards" (#234)

* Add "forgetCards" and "relearnCards"

* Add unit tests

Co-authored-by: Tsung-Po Sun <tsungpo.sun@smartnews.com>
This commit is contained in:
Tsung-Po Sun(Munehiro) 2021-03-05 13:02:57 +09:00 committed by GitHub
parent 131a1c7cfc
commit a4d723de3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 0 deletions

View File

@ -306,3 +306,49 @@
"error": null
}
```
* **forgetCards**
Forget cards, making the cards new again.
*Sample request*:
```json
{
"action": "forgetCards",
"version": 6,
"params": {
"cards": [1498938915662, 1502098034048]
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
* **relearnCards**
Make cards be "relearning".
*Sample request*:
```json
{
"action": "relearnCards",
"version": 6,
"params": {
"cards": [1498938915662, 1502098034048]
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```

View File

@ -1035,6 +1035,22 @@ class AnkiConnect:
return result
@util.api()
def forgetCards(self, cards):
self.startEditing()
scids = anki.utils.ids2str(cards)
self.collection().db.execute('update cards set type=0, queue=0, left=0, ivl=0, due=0, odue=0, factor=0 where id in ' + scids)
self.stopEditing()
@util.api()
def relearnCards(self, cards):
self.startEditing()
scids = anki.utils.ids2str(cards)
self.collection().db.execute('update cards set type=3, queue=1 where id in ' + scids)
self.stopEditing()
@util.api()
def cardReviews(self, deck, startID):
return self.database().all(

View File

@ -74,6 +74,11 @@ class TestCards(unittest.TestCase):
for i, cardInfo in enumerate(cardsInfo):
self.assertEqual(cardInfo['cardId'], cardIds[i])
# forgetCards
util.invoke('forgetCards', cards=cardIds)
# relearnCards
util.invoke('relearnCards', cards=cardIds)
if __name__ == '__main__':
unittest.main()