implement setSpecificValueOfCard for user @TobiasWehrum (#303)
Co-authored-by: thiswillbeyourgithub <github@32mail.33mail.comm>
This commit is contained in:
parent
a5aecfceee
commit
54a7105bf9
29
README.md
29
README.md
@ -238,6 +238,35 @@ corresponding to when the API was available for use.
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
* **setSpecificValueOfCard**
|
||||
|
||||
Sets specific value of a single card. Given the risk of wreaking havor in the database when changing some of the values of a card, some of the keys require the argument "warning_check" set to True.
|
||||
This can be used to set a card's flag, change it's ease factor, change the review order in a filtered deck and change the column "data" (not currently used by anki apparantly), and many other values.
|
||||
A list of values and explanation of their respective utility can be found at [AnkiDroid's wiki](https://github.com/ankidroid/Anki-Android/wiki/Database-Structure).
|
||||
|
||||
*Sample request*:
|
||||
```json
|
||||
{
|
||||
"action": "setSpecificValueOfCard",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"card": 1483959291685,
|
||||
"keys": ["flags", "odue"],
|
||||
"newValues": ["1", "-100"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*Sample result*:
|
||||
```json
|
||||
{
|
||||
"result": [true, true],
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
* **suspend**
|
||||
|
||||
Suspend cards by card ID; returns `true` if successful (at least one card wasn't already suspended) or `false`
|
||||
|
@ -833,6 +833,38 @@ class AnkiConnect:
|
||||
|
||||
return couldSetEaseFactors
|
||||
|
||||
@util.api()
|
||||
def setSpecificValueOfCard(self, card, keys,
|
||||
newValues, warning_check=False):
|
||||
if isinstance(card, list):
|
||||
print("card has to be int, not list")
|
||||
return False
|
||||
|
||||
if not isinstance(keys, list) or not isinstance(newValues, list):
|
||||
print("keys and newValues have to be lists.")
|
||||
return False
|
||||
|
||||
if len(newValues) != len(keys):
|
||||
print("Invalid list lengths.")
|
||||
return False
|
||||
|
||||
for key in keys:
|
||||
if key in ["did", "id", "ivl", "lapses", "left", "mod", "nid",
|
||||
"odid", "odue", "ord", "queue", "reps", "type", "usn"]:
|
||||
if warning_check is False:
|
||||
return False
|
||||
|
||||
result = []
|
||||
try:
|
||||
ankiCard = self.getCard(card)
|
||||
for i, key in enumerate(keys):
|
||||
setattr(ankiCard, key, newValues[i])
|
||||
ankiCard.flush()
|
||||
result.append(True)
|
||||
except Exception as e:
|
||||
result.append([False, str(e)])
|
||||
return result
|
||||
|
||||
|
||||
@util.api()
|
||||
def getEaseFactors(self, cards):
|
||||
|
Loading…
Reference in New Issue
Block a user