Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
implement setSpecificValueOfCard for user @TobiasWehrum (#303)
Browse files Browse the repository at this point in the history
Co-authored-by: thiswillbeyourgithub <[email protected]>
  • Loading branch information
thiswillbeyourgithub and thiswillbeyourgithub authored Feb 23, 2022
1 parent a5aecfc commit 54a7105
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
32 changes: 32 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,38 @@ def setEaseFactors(self, cards, easeFactors):

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):
Expand Down

0 comments on commit 54a7105

Please sign in to comment.