Add getDecks function

This commit is contained in:
David Bailey 2017-08-13 09:02:59 +01:00
parent e50f2af06b
commit 6da8481b07
2 changed files with 43 additions and 0 deletions

View File

@ -537,6 +537,20 @@ class AnkiBridge:
return []
def getDecks(self, cards):
decks = {}
for card in cards:
did = self.collection().db.scalar('select did from cards where id = ?', card)
deck = self.collection().decks.get(did)['name']
if deck in decks:
decks[deck].append(card)
else:
decks[deck] = [card]
return decks
def changeDeck(self, cards, deck):
self.startEditing()
@ -837,6 +851,11 @@ class AnkiConnect:
return self.anki.findCards(query)
@webApi
def getDecks(self, cards):
return self.anki.getDecks(cards)
@webApi
def changeDeck(self, cards, deck):
return self.anki.changeDeck(cards, deck)

View File

@ -511,6 +511,30 @@ Below is a list of currently supported actions. Requests with invalid actions or
]
```
* **getDecks**
Accepts an array of card IDs and returns an object with each deck name as a key, and its value an array of the given
cards which belong to it.
*Sample request*:
```
{
"action": "getDecks",
"params": {
"cards": [1502298036657, 1502298033753, 1502032366472]
}
}
```
*Sample response*:
```
{
"Default": [1502032366472],
"Japanese::JLPT N3": [1502298036657, 1502298033753]
}
```
* **changeDeck**
Moves cards with the given IDs to a different deck, creating the deck if it doesn't exist yet.