From a4d723de3ef0e57d28e2c3c70e460f69b5156058 Mon Sep 17 00:00:00 2001 From: "Tsung-Po Sun(Munehiro)" <33222939+hrdrq@users.noreply.github.com> Date: Fri, 5 Mar 2021 13:02:57 +0900 Subject: [PATCH] Add "forgetCards" and "relearnCards" (#234) * Add "forgetCards" and "relearnCards" * Add unit tests Co-authored-by: Tsung-Po Sun --- actions/cards.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ plugin/__init__.py | 16 ++++++++++++++++ tests/test_cards.py | 5 +++++ 3 files changed, 67 insertions(+) diff --git a/actions/cards.md b/actions/cards.md index bd5a983..3857bb8 100644 --- a/actions/cards.md +++ b/actions/cards.md @@ -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 + } + ``` diff --git a/plugin/__init__.py b/plugin/__init__.py index 1517146..def3ba6 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -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( diff --git a/tests/test_cards.py b/tests/test_cards.py index 233a361..f08be4f 100755 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -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()