diff --git a/AnkiConnect.py b/AnkiConnect.py index c6f4897..95b1326 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -507,6 +507,23 @@ class AnkiBridge: return [] + def changeDeck(self, cards, deck): + self.startEditing() + + did = self.window().col.decks.id(deck) + mod = anki.utils.intTime() + usn = self.window().col.usn() + + # normal cards + scids = anki.utils.ids2str(cards) + # remove any cards from filtered deck first + self.window().col.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.stopEditing() + + def cardsToNotes(self, cards): return self.window().col.db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards)) @@ -785,6 +802,11 @@ class AnkiConnect: return self.anki.findCards(query) + @webApi + def changeDeck(self, cards, deck): + return self.anki.changeDeck(cards, deck) + + @webApi def cardsToNotes(self, cards): return self.anki.cardsToNotes(cards) diff --git a/README.md b/README.md index 43b9c63..e728f29 100644 --- a/README.md +++ b/README.md @@ -490,6 +490,26 @@ Below is a list of currently supported actions. Requests with invalid actions or ] ``` +* **changeDeck** + + Moves cards with the given IDs to a different deck, creating the deck if it doesn't exist yet. + + *Sample request*: + ``` + { + "action": "changeDeck", + "params": { + "cards": [1502098034045, 1502098034048, 1502298033753], + "deck": "Japanese::JLPT N3" + } + } + ``` + + *Sample response*: + ``` + null + ``` + * **cardsToNotes** Returns an (unordered) array of note IDs for the given card IDs. For cards with the same note, the ID is only