Merge pull request #18 from techdavid/addtags-and-suspend

Add tagging and suspend functions
This commit is contained in:
Alex Yatskov 2017-08-03 17:03:40 -07:00 committed by GitHub
commit 4e9f96460b
2 changed files with 161 additions and 17 deletions

View File

@ -375,6 +375,17 @@ class AnkiBridge:
return note
def addTags(self, notes, tags, add=True):
aqt.mw.col.tags.bulkAdd(notes, tags, add)
def suspend(self, cards, suspend=True):
if suspend:
aqt.mw.col.sched.suspendCards(cards)
else:
aqt.mw.col.sched.unsuspendCards(cards)
def startEditing(self):
self.window().requireReset()
@ -449,6 +460,20 @@ class AnkiBridge:
return deck['name']
def findNotes(self, query=None):
if query is not None:
return aqt.mw.col.findNotes(query)
else:
return []
def findCards(self, query=None):
if query is not None:
return aqt.mw.col.findCards(query)
else:
return []
def guiBrowse(self, query=None):
browser = aqt.dialogs.open('Browser', self.window())
browser.activateWindow()
@ -463,13 +488,6 @@ class AnkiBridge:
return browser.model.cards
def browse(self, query=None):
if query is not None:
return aqt.mw.col.findCards(query)
else:
return []
def guiAddCards(self):
addCards = aqt.dialogs.open('AddCards', self.window())
addCards.activateWindow()
@ -662,6 +680,26 @@ class AnkiConnect:
return results
@webApi
def addTags(self, notes, tags, add=True):
return self.anki.addTags(notes, tags, add)
@webApi
def removeTags(self, notes, tags):
return self.anki.addTags(notes, tags, False)
@webApi
def suspend(self, cards, suspend=True):
return self.anki.suspend(cards, suspend)
@webApi
def unsuspend(self, cards):
return self.anki.suspend(cards, False)
@webApi
def upgrade(self):
response = QMessageBox.question(
@ -691,13 +729,18 @@ class AnkiConnect:
@webApi
def guiBrowse(self, query=None):
return self.anki.guiBrowse(query)
def findNotes(self, query=None):
return self.anki.findNotes(query)
@webApi
def browse(self, query=None):
return self.anki.browse(query)
def findCards(self, query=None):
return self.anki.findCards(query)
@webApi
def guiBrowse(self, query=None):
return self.anki.guiBrowse(query)
@webApi

113
README.md
View File

@ -305,14 +305,115 @@ Below is a list of currently supported actions. Requests with invalid actions or
]
```
* **guiBrowse**
* **addTags**
Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found.
Adds tags to notes by note ID.
*Sample request*:
```
{
"action": "guiBrowse",
"action": "addTags",
"params": {
"notes": [1483959289817, 1483959291695],
"tags": "european-languages"
}
}
```
*Sample response*:
```
null
```
* **removeTags**
Remove tags from notes by note ID.
*Sample request*:
```
{
"action": "removeTags",
"params": {
"notes": [1483959289817, 1483959291695],
"tags": "european-languages"
}
}
```
*Sample response*:
```
null
```
* **suspend**
Suspend cards by card ID.
*Sample request*:
```
{
"action": "suspend",
"params": {
"cards": [1483959291685, 1483959293217]
}
}
```
*Sample response*:
```
null
```
* **unsuspend**
Unsuspend cards by card ID.
*Sample request*:
```
{
"action": "unsuspend",
"params": {
"cards": [1483959291685, 1483959293217]
}
}
```
*Sample response*:
```
null
```
* **findNotes**
Returns an array of note IDs for a given query (same query syntax as **guiBrowse**).
*Sample request*:
```
{
"action": "findCards",
"params": {
"query": "deck:current"
}
}
```
*Sample response*:
```
[
1483959289817,
1483959291695
]
```
* **findCards**
Returns an array of card IDs for a given query (functionally identical to **guiBrowse** but doesn't use the GUI
for better performance).
*Sample request*:
```
{
"action": "findCards",
"params": {
"query": "deck:current"
}
@ -328,14 +429,14 @@ Below is a list of currently supported actions. Requests with invalid actions or
]
```
* **browse**
* **guiBrowse**
Functionally identical to **guiBrowse**, but accesses the database without using the GUI for increased performance.
Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found.
*Sample request*:
```
{
"action": "browse",
"action": "guiBrowse",
"params": {
"query": "deck:current"
}