M AnkiConnect.py => AnkiConnect.py +22 -0
@@ 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))
@@ 786,6 803,11 @@ class AnkiConnect:
@webApi
+ def changeDeck(self, cards, deck):
+ return self.anki.changeDeck(cards, deck)
+
+
+ @webApi
def cardsToNotes(self, cards):
return self.anki.cardsToNotes(cards)
M README.md => README.md +20 -0
@@ 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