Merge pull request #25 from techdavid/add-getdecks-and-deletedecks
Add getDecks and deleteDecks functions
This commit is contained in:
commit
792a5c0134
@ -537,6 +537,20 @@ class AnkiBridge:
|
|||||||
return []
|
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):
|
def changeDeck(self, cards, deck):
|
||||||
self.startEditing()
|
self.startEditing()
|
||||||
|
|
||||||
@ -554,6 +568,14 @@ class AnkiBridge:
|
|||||||
self.stopEditing()
|
self.stopEditing()
|
||||||
|
|
||||||
|
|
||||||
|
def deleteDecks(self, decks, cardsToo=False):
|
||||||
|
self.startEditing()
|
||||||
|
for deck in decks:
|
||||||
|
id = self.collection().decks.id(deck)
|
||||||
|
self.collection().decks.rem(id, cardsToo)
|
||||||
|
self.stopEditing()
|
||||||
|
|
||||||
|
|
||||||
def cardsToNotes(self, cards):
|
def cardsToNotes(self, cards):
|
||||||
return self.collection().db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards))
|
return self.collection().db.list('select distinct nid from cards where id in ' + anki.utils.ids2str(cards))
|
||||||
|
|
||||||
@ -837,11 +859,21 @@ class AnkiConnect:
|
|||||||
return self.anki.findCards(query)
|
return self.anki.findCards(query)
|
||||||
|
|
||||||
|
|
||||||
|
@webApi
|
||||||
|
def getDecks(self, cards):
|
||||||
|
return self.anki.getDecks(cards)
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def changeDeck(self, cards, deck):
|
def changeDeck(self, cards, deck):
|
||||||
return self.anki.changeDeck(cards, deck)
|
return self.anki.changeDeck(cards, deck)
|
||||||
|
|
||||||
|
|
||||||
|
@webApi
|
||||||
|
def deleteDecks(self, decks, cardsToo=False):
|
||||||
|
return self.anki.deleteDecks(decks, cardsToo)
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def cardsToNotes(self, cards):
|
def cardsToNotes(self, cards):
|
||||||
return self.anki.cardsToNotes(cards)
|
return self.anki.cardsToNotes(cards)
|
||||||
|
45
README.md
45
README.md
@ -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**
|
* **changeDeck**
|
||||||
|
|
||||||
Moves cards with the given IDs to a different deck, creating the deck if it doesn't exist yet.
|
Moves cards with the given IDs to a different deck, creating the deck if it doesn't exist yet.
|
||||||
@ -530,6 +554,27 @@ Below is a list of currently supported actions. Requests with invalid actions or
|
|||||||
```
|
```
|
||||||
null
|
null
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* **deleteDecks**
|
||||||
|
|
||||||
|
Deletes decks with the given names. If `cardsToo` is `true` (defaults to `false` if unspecified), the cards within
|
||||||
|
the deleted decks will also be deleted; otherwise they will be moved to the default deck.
|
||||||
|
|
||||||
|
*Sample request*:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"action": "deleteDecks",
|
||||||
|
"params": {
|
||||||
|
"decks": ["Japanese::JLPT N5", "Easy Spanish"],
|
||||||
|
"cardsToo": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Sample response*:
|
||||||
|
```
|
||||||
|
null
|
||||||
|
```
|
||||||
|
|
||||||
* **cardsToNotes**
|
* **cardsToNotes**
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user