Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
98e0bb35fb | ||
|
a382fdfe85 | ||
|
8bfb4049dc | ||
|
6eea9f9db4 | ||
|
c89dbf2062 | ||
|
ba67c52d9b | ||
|
cc027f8ab8 | ||
|
dc96cdc76c | ||
|
6a2cc2dec1 | ||
|
172d1fb20f | ||
|
0514569621 | ||
|
81c39a2e42 | ||
|
f52e0c2e24 | ||
|
aab9346deb | ||
|
7c171d6722 | ||
|
306103c618 | ||
|
1c428c8627 | ||
|
b77327fb00 | ||
4837823bce | |||
24cdeeb612 | |||
00dffe579d | |||
|
bbf271c5ac | ||
|
2f7bc2e78e | ||
|
d27f54a4fe | ||
|
2996476e03 | ||
|
510f47fd08 | ||
|
977871257a | ||
|
29260d6a00 | ||
|
a17c4e42da | ||
|
50d062e6ca |
89
.github/workflows/tests.yml
vendored
89
.github/workflows/tests.yml
vendored
@ -1,89 +0,0 @@
|
||||
name: Tests
|
||||
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
run-tests:
|
||||
name: ${{ matrix.name }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- name: Anki 2.1.45
|
||||
python: 3.8
|
||||
environment: py38-anki2.1.45
|
||||
- name: Anki 2.1.46
|
||||
python: 3.8
|
||||
environment: py38-anki2.1.46
|
||||
- name: Anki 2.1.47
|
||||
python: 3.8
|
||||
environment: py38-anki2.1.47
|
||||
- name: Anki 2.1.48
|
||||
python: 3.8
|
||||
environment: py38-anki2.1.48
|
||||
- name: Anki 2.1.49
|
||||
python: 3.8
|
||||
environment: py38-anki2.1.49
|
||||
- name: Anki 2.1.50 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.50-qt5
|
||||
- name: Anki 2.1.50 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.50-qt6
|
||||
- name: Anki 2.1.51 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.51-qt5
|
||||
- name: Anki 2.1.51 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.51-qt6
|
||||
- name: Anki 2.1.52 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.52-qt5
|
||||
- name: Anki 2.1.52 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.52-qt6
|
||||
- name: Anki 2.1.53 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.53-qt5
|
||||
- name: Anki 2.1.53 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.53-qt6
|
||||
- name: Anki 2.1.54 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.54-qt5
|
||||
- name: Anki 2.1.54 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.54-qt6
|
||||
- name: Anki 2.1.55 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.55-qt5
|
||||
- name: Anki 2.1.55 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.55-qt6
|
||||
- name: Anki 2.1.56 (Qt5)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.56-qt5
|
||||
- name: Anki 2.1.56 (Qt6)
|
||||
python: 3.9
|
||||
environment: py39-anki2.1.56-qt6
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y pyqt5-dev-tools xvfb jq
|
||||
|
||||
- name: Setup Python ${{ matrix.python }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python }}
|
||||
|
||||
- name: Install tox
|
||||
run: pip install 'tox==3.28.0'
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run tests
|
||||
run: tox -vvve ${{ matrix.environment }} -- --forked --verbose
|
691
README.md
691
README.md
@ -920,7 +920,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
|
||||
#### `deleteDecks`
|
||||
|
||||
* Deletes decks with the given names.
|
||||
* Deletes decks with the given names.
|
||||
The argument `cardsToo` *must* be specified and set to `true`.
|
||||
|
||||
<details>
|
||||
@ -1226,6 +1226,10 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
* Invokes the *Card Browser* dialog and searches for a given query. Returns an array of identifiers of the cards that
|
||||
were found. Query syntax is [documented here](https://docs.ankiweb.net/searching.html).
|
||||
|
||||
Optionally, the `reorderCards` property can be provided to reorder the cards shown in the *Card Browser*.
|
||||
This is an array including the `order` and `columnId` objects. `order` can be either `ascending` or `descending` while `columnId` can be one of several column identifiers (as documented in the [Anki source code](https://github.com/ankitects/anki/blob/main/rslib/src/browser_table.rs)).
|
||||
The specified column needs to be visible in the *Card Browser*.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
@ -1234,7 +1238,11 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
"action": "guiBrowse",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"query": "deck:current"
|
||||
"query": "deck:current",
|
||||
"reorderCards": {
|
||||
"order": "descending",
|
||||
"columnId": "noteCrt"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -1251,6 +1259,36 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `guiSelectNote`
|
||||
|
||||
* Finds the open instance of the *Card Browser* dialog and selects a note given a note identifier.
|
||||
Returns `true` if the *Card Browser* is open, `false` otherwise.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "guiSelectNote",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"note": 1494723142483
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": true,
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `guiSelectedNotes`
|
||||
|
||||
* Finds the open instance of the *Card Browser* dialog and returns an array of identifiers of the notes that are
|
||||
@ -1950,7 +1988,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Samples results:</i></summary>
|
||||
<summary><i>Sample results:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -2019,11 +2057,11 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
```json
|
||||
{
|
||||
"action": "apiReflect",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"scopes": ["actions", "invalidType"],
|
||||
"actions": ["apiReflect", "invalidMethod"]
|
||||
},
|
||||
"version": 6
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
@ -2094,6 +2132,33 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `getActiveProfile`
|
||||
|
||||
* Retrieve the active profile.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "getActiveProfile",
|
||||
"version": 6
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": "User 1",
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
#### `loadProfile`
|
||||
|
||||
* Selects the profile specified in request.
|
||||
@ -2104,10 +2169,10 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
```json
|
||||
{
|
||||
"action": "loadProfile",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"name": "user1"
|
||||
},
|
||||
"version": 6
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
@ -2323,6 +2388,381 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `findModelsById`
|
||||
|
||||
* Gets a list of models for the provided model IDs from the current user.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "findModelsById",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"modelIds": [1704387367119, 1704387398570]
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"id": 1704387367119,
|
||||
"name": "Basic",
|
||||
"type": 0,
|
||||
"mod": 1704387367,
|
||||
"usn": -1,
|
||||
"sortf": 0,
|
||||
"did": null,
|
||||
"tmpls": [
|
||||
{
|
||||
"name": "Card 1",
|
||||
"ord": 0,
|
||||
"qfmt": "{{Front}}",
|
||||
"afmt": "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}",
|
||||
"bqfmt": "",
|
||||
"bafmt": "",
|
||||
"did": null,
|
||||
"bfont": "",
|
||||
"bsize": 0,
|
||||
"id": 9176047152973362695
|
||||
}
|
||||
],
|
||||
"flds": [
|
||||
{
|
||||
"name": "Front",
|
||||
"ord": 0,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": 2453723143453745216,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
},
|
||||
{
|
||||
"name": "Back",
|
||||
"ord": 1,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": -4853200230425436781,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
}
|
||||
],
|
||||
"css": ".card {\n font-family: arial;\n font-size: 20px;\n text-align: center;\n color: black;\n background-color: white;\n}\n",
|
||||
"latexPre": "\\documentclass[12pt]{article}\n\\special{papersize=3in,5in}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb,amsmath}\n\\pagestyle{empty}\n\\setlength{\\parindent}{0in}\n\\begin{document}\n",
|
||||
"latexPost": "\\end{document}",
|
||||
"latexsvg": false,
|
||||
"req": [
|
||||
[
|
||||
0,
|
||||
"any",
|
||||
[
|
||||
0
|
||||
]
|
||||
]
|
||||
],
|
||||
"originalStockKind": 1
|
||||
},
|
||||
{
|
||||
"id": 1704387398570,
|
||||
"name": "Basic (and reversed card)",
|
||||
"type": 0,
|
||||
"mod": 1704387398,
|
||||
"usn": -1,
|
||||
"sortf": 0,
|
||||
"did": null,
|
||||
"tmpls": [
|
||||
{
|
||||
"name": "Card 1",
|
||||
"ord": 0,
|
||||
"qfmt": "{{Front}}",
|
||||
"afmt": "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}",
|
||||
"bqfmt": "",
|
||||
"bafmt": "",
|
||||
"did": null,
|
||||
"bfont": "",
|
||||
"bsize": 0,
|
||||
"id": 1689886528158874152
|
||||
},
|
||||
{
|
||||
"name": "Card 2",
|
||||
"ord": 1,
|
||||
"qfmt": "{{Back}}",
|
||||
"afmt": "{{FrontSide}}\n\n<hr id=answer>\n\n{{Front}}",
|
||||
"bqfmt": "",
|
||||
"bafmt": "",
|
||||
"did": null,
|
||||
"bfont": "",
|
||||
"bsize": 0,
|
||||
"id": -7839609225644824587
|
||||
}
|
||||
],
|
||||
"flds": [
|
||||
{
|
||||
"name": "Front",
|
||||
"ord": 0,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": -7787837672455357996,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
},
|
||||
{
|
||||
"name": "Back",
|
||||
"ord": 1,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": 6364828289839985081,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
}
|
||||
],
|
||||
"css": ".card {\n font-family: arial;\n font-size: 20px;\n text-align: center;\n color: black;\n background-color: white;\n}\n",
|
||||
"latexPre": "\\documentclass[12pt]{article}\n\\special{papersize=3in,5in}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb,amsmath}\n\\pagestyle{empty}\n\\setlength{\\parindent}{0in}\n\\begin{document}\n",
|
||||
"latexPost": "\\end{document}",
|
||||
"latexsvg": false,
|
||||
"req": [
|
||||
[
|
||||
0,
|
||||
"any",
|
||||
[
|
||||
0
|
||||
]
|
||||
],
|
||||
[
|
||||
1,
|
||||
"any",
|
||||
[
|
||||
1
|
||||
]
|
||||
]
|
||||
],
|
||||
"originalStockKind": 1
|
||||
}
|
||||
],
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
#### `findModelsByName`
|
||||
|
||||
* Gets a list of models for the provided model names from the current user.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "findModelsByName",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"modelNames": ["Basic", "Basic (and reversed card)"]
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"id": 1704387367119,
|
||||
"name": "Basic",
|
||||
"type": 0,
|
||||
"mod": 1704387367,
|
||||
"usn": -1,
|
||||
"sortf": 0,
|
||||
"did": null,
|
||||
"tmpls": [
|
||||
{
|
||||
"name": "Card 1",
|
||||
"ord": 0,
|
||||
"qfmt": "{{Front}}",
|
||||
"afmt": "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}",
|
||||
"bqfmt": "",
|
||||
"bafmt": "",
|
||||
"did": null,
|
||||
"bfont": "",
|
||||
"bsize": 0,
|
||||
"id": 9176047152973362695
|
||||
}
|
||||
],
|
||||
"flds": [
|
||||
{
|
||||
"name": "Front",
|
||||
"ord": 0,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": 2453723143453745216,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
},
|
||||
{
|
||||
"name": "Back",
|
||||
"ord": 1,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": -4853200230425436781,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
}
|
||||
],
|
||||
"css": ".card {\n font-family: arial;\n font-size: 20px;\n text-align: center;\n color: black;\n background-color: white;\n}\n",
|
||||
"latexPre": "\\documentclass[12pt]{article}\n\\special{papersize=3in,5in}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb,amsmath}\n\\pagestyle{empty}\n\\setlength{\\parindent}{0in}\n\\begin{document}\n",
|
||||
"latexPost": "\\end{document}",
|
||||
"latexsvg": false,
|
||||
"req": [
|
||||
[
|
||||
0,
|
||||
"any",
|
||||
[
|
||||
0
|
||||
]
|
||||
]
|
||||
],
|
||||
"originalStockKind": 1
|
||||
},
|
||||
{
|
||||
"id": 1704387398570,
|
||||
"name": "Basic (and reversed card)",
|
||||
"type": 0,
|
||||
"mod": 1704387398,
|
||||
"usn": -1,
|
||||
"sortf": 0,
|
||||
"did": null,
|
||||
"tmpls": [
|
||||
{
|
||||
"name": "Card 1",
|
||||
"ord": 0,
|
||||
"qfmt": "{{Front}}",
|
||||
"afmt": "{{FrontSide}}\n\n<hr id=answer>\n\n{{Back}}",
|
||||
"bqfmt": "",
|
||||
"bafmt": "",
|
||||
"did": null,
|
||||
"bfont": "",
|
||||
"bsize": 0,
|
||||
"id": 1689886528158874152
|
||||
},
|
||||
{
|
||||
"name": "Card 2",
|
||||
"ord": 1,
|
||||
"qfmt": "{{Back}}",
|
||||
"afmt": "{{FrontSide}}\n\n<hr id=answer>\n\n{{Front}}",
|
||||
"bqfmt": "",
|
||||
"bafmt": "",
|
||||
"did": null,
|
||||
"bfont": "",
|
||||
"bsize": 0,
|
||||
"id": -7839609225644824587
|
||||
}
|
||||
],
|
||||
"flds": [
|
||||
{
|
||||
"name": "Front",
|
||||
"ord": 0,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": -7787837672455357996,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
},
|
||||
{
|
||||
"name": "Back",
|
||||
"ord": 1,
|
||||
"sticky": false,
|
||||
"rtl": false,
|
||||
"font": "Arial",
|
||||
"size": 20,
|
||||
"description": "",
|
||||
"plainText": false,
|
||||
"collapsed": false,
|
||||
"excludeFromSearch": false,
|
||||
"id": 6364828289839985081,
|
||||
"tag": null,
|
||||
"preventDeletion": false
|
||||
}
|
||||
],
|
||||
"css": ".card {\n font-family: arial;\n font-size: 20px;\n text-align: center;\n color: black;\n background-color: white;\n}\n",
|
||||
"latexPre": "\\documentclass[12pt]{article}\n\\special{papersize=3in,5in}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb,amsmath}\n\\pagestyle{empty}\n\\setlength{\\parindent}{0in}\n\\begin{document}\n",
|
||||
"latexPost": "\\end{document}",
|
||||
"latexsvg": false,
|
||||
"req": [
|
||||
[
|
||||
0,
|
||||
"any",
|
||||
[
|
||||
0
|
||||
]
|
||||
],
|
||||
[
|
||||
1,
|
||||
"any",
|
||||
[
|
||||
1
|
||||
]
|
||||
]
|
||||
],
|
||||
"originalStockKind": 1
|
||||
}
|
||||
],
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `modelFieldNames`
|
||||
|
||||
* Gets the complete list of field names for the provided model name.
|
||||
@ -2455,13 +2895,13 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
#### `createModel`
|
||||
|
||||
* Creates a new model to be used in Anki. User must provide the `modelName`, `inOrderFields` and `cardTemplates` to be
|
||||
used in the model. There are optional fields `css` and `isCloze`. If not specified, `css` will use the default Anki css and `isCloze` will be equal to `False`. If `isCloze` is `True` then model will be created as Cloze.
|
||||
used in the model. There are optional fields `css` and `isCloze`. If not specified, `css` will use the default Anki css and `isCloze` will be equal to `false`. If `isCloze` is `true` then model will be created as Cloze.
|
||||
|
||||
Optionally the `Name` field can be provided for each entry of `cardTemplates`. By default the
|
||||
card names will be `Card 1`, `Card 2`, and so on.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request</i></summary>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -2485,7 +2925,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result</i></summary>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -2575,7 +3015,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result</i></summary>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -2613,7 +3053,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result</i></summary>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -2773,7 +3213,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "modelTemplateRemove",
|
||||
"action": "modelTemplateReposition",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"modelName": "Basic",
|
||||
@ -3026,7 +3466,7 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "modelFieldSetFont",
|
||||
"action": "modelFieldSetFontSize",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"modelName": "Basic",
|
||||
@ -3179,55 +3619,36 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
#### `addNotes`
|
||||
|
||||
* Creates multiple notes using the given deck and model, with the provided field values and tags. Returns an array of
|
||||
identifiers of the created notes (notes that could not be created will have a `null` identifier). Please see the
|
||||
documentation for `addNote` for an explanation of objects in the `notes` array.
|
||||
identifiers of the created notes. In the event of any errors, all errors are gathered and returned.
|
||||
* Please see the documentation for `addNote` for an explanation of objects in the `notes` array.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "addNotes",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"notes": [
|
||||
{
|
||||
"deckName": "Default",
|
||||
"modelName": "Basic",
|
||||
"fields": {
|
||||
"Front": "front content",
|
||||
"Back": "back content"
|
||||
},
|
||||
"tags": [
|
||||
"yomichan"
|
||||
],
|
||||
"audio": [{
|
||||
"url": "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=猫&kana=ねこ",
|
||||
"filename": "yomichan_ねこ_猫.mp3",
|
||||
"skipHash": "7e2c2f954ef6051373ba916f000168dc",
|
||||
"fields": [
|
||||
"Front"
|
||||
]
|
||||
}],
|
||||
"video": [{
|
||||
"url": "https://cdn.videvo.net/videvo_files/video/free/2015-06/small_watermarked/Contador_Glam_preview.mp4",
|
||||
"filename": "countdown.mp4",
|
||||
"skipHash": "4117e8aab0d37534d9c8eac362388bbe",
|
||||
"fields": [
|
||||
"Back"
|
||||
]
|
||||
}],
|
||||
"picture": [{
|
||||
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/A_black_cat_named_Tilly.jpg/220px-A_black_cat_named_Tilly.jpg",
|
||||
"filename": "black_cat.jpg",
|
||||
"skipHash": "8d6e4646dfae812bf39651b59d7429ce",
|
||||
"fields": [
|
||||
"Back"
|
||||
]
|
||||
}]
|
||||
"action":"addNotes",
|
||||
"version":6,
|
||||
"params":{
|
||||
"notes":[
|
||||
{
|
||||
"deckName":"College::PluginDev",
|
||||
"modelName":"non_existent_model",
|
||||
"fields":{
|
||||
"Front":"front",
|
||||
"Back":"bak"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"deckName":"College::PluginDev",
|
||||
"modelName":"Basic",
|
||||
"fields":{
|
||||
"Front":"front",
|
||||
"Back":"bak"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
@ -3237,8 +3658,8 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
|
||||
```json
|
||||
{
|
||||
"result": [1496198395707, null],
|
||||
"error": null
|
||||
"result":null,
|
||||
"error":"['model was not found: non_existent_model']"
|
||||
}
|
||||
```
|
||||
</details>
|
||||
@ -3285,6 +3706,70 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `canAddNotesWithErrorDetail`
|
||||
|
||||
* Accepts an array of objects which define parameters for candidate notes (see `addNote`) and returns an array of
|
||||
objects with fields `canAdd` and `error`.
|
||||
|
||||
* `canAdd` indicates whether or not the parameters at the corresponding index could be used to create a new note.
|
||||
* `error` contains an explanation of why a note cannot be added.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "canAddNotesWithErrorDetail",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"notes": [
|
||||
{
|
||||
"deckName": "Default",
|
||||
"modelName": "Basic",
|
||||
"fields": {
|
||||
"Front": "front content",
|
||||
"Back": "back content"
|
||||
},
|
||||
"tags": [
|
||||
"yomichan"
|
||||
]
|
||||
},
|
||||
{
|
||||
"deckName": "Default",
|
||||
"modelName": "Basic",
|
||||
"fields": {
|
||||
"Front": "front content 2",
|
||||
"Back": "back content 2"
|
||||
},
|
||||
"tags": [
|
||||
"yomichan"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"canAdd": false,
|
||||
"error": "cannot create note because it is a duplicate"
|
||||
},
|
||||
{
|
||||
"canAdd": true
|
||||
}
|
||||
],
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `updateNoteFields`
|
||||
|
||||
* Modify the fields of an existing note. You can also include audio, video, or picture files which will be added to the note with an
|
||||
@ -3372,6 +3857,45 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": null,
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
#### `updateNoteModel`
|
||||
|
||||
* Update the model, fields, and tags of an existing note.
|
||||
This allows you to change the note's model, update its fields with new content, and set new tags.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "updateNoteModel",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"note": {
|
||||
"id": 1514547547030,
|
||||
"modelName": "NewModel",
|
||||
"fields": {
|
||||
"NewField1": "new field 1",
|
||||
"NewField2": "new field 2",
|
||||
"NewField3": "new field 3"
|
||||
},
|
||||
"tags": ["new", "updated", "tags"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
@ -3404,7 +3928,6 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
@ -3416,7 +3939,6 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### `getNoteTags`
|
||||
@ -3435,7 +3957,6 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
@ -3447,7 +3968,6 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### `addTags`
|
||||
@ -3654,8 +4174,8 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
|
||||
#### `notesInfo`
|
||||
|
||||
* Returns a list of objects containing for each note ID the note fields, tags, note type and the cards belonging to
|
||||
the note.
|
||||
* Returns a list of objects containing for each note ID the note fields, tags, note type, modification time,the cards belonging to
|
||||
the note and the profile where the note was created.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
@ -3679,12 +4199,49 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
"result": [
|
||||
{
|
||||
"noteId":1502298033753,
|
||||
"profile": "User_1",
|
||||
"modelName": "Basic",
|
||||
"tags":["tag","another_tag"],
|
||||
"fields": {
|
||||
"Front": {"value": "front content", "order": 0},
|
||||
"Back": {"value": "back content", "order": 1}
|
||||
}
|
||||
},
|
||||
"mod": 1718377864,
|
||||
"cards": [1498938915662]
|
||||
}
|
||||
],
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
s
|
||||
#### `notesModTime`
|
||||
|
||||
* Returns a list of objects containings for each note ID the modification time.
|
||||
|
||||
<details>
|
||||
<summary><i>Sample request:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "notesModTime",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"notes": [1502298033753]
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><i>Sample result:</i></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"noteId": 1498938915662,
|
||||
"mod": 1629454092
|
||||
}
|
||||
],
|
||||
"error": null
|
||||
@ -3830,8 +4387,8 @@ Search parameters are passed to Anki, check the docs for more information: https
|
||||
|
||||
```json
|
||||
{
|
||||
"error": null,
|
||||
"result": "<center> lots of HTML here </center>"
|
||||
"result": "<center> lots of HTML here </center>",
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
@ -15,10 +15,11 @@
|
||||
|
||||
import aqt
|
||||
|
||||
required_anki_version = (23, 10, 0)
|
||||
anki_version = tuple(int(segment) for segment in aqt.appVersion.split("."))
|
||||
|
||||
if anki_version < (2, 1, 45):
|
||||
raise Exception("Minimum Anki version supported: 2.1.45")
|
||||
if anki_version < required_anki_version:
|
||||
raise Exception(f"Minimum Anki version supported: {required_anki_version[0]}.{required_anki_version[1]}.{required_anki_version[2]}")
|
||||
|
||||
import base64
|
||||
import glob
|
||||
@ -41,6 +42,7 @@ from anki.exporting import AnkiPackageExporter
|
||||
from anki.importing import AnkiPackageImporter
|
||||
from anki.notes import Note
|
||||
from anki.errors import NotFoundError
|
||||
from anki.scheduler.base import ScheduleCardsAsNew
|
||||
from aqt.qt import Qt, QTimer, QMessageBox, QCheckBox
|
||||
|
||||
from .web import format_exception_reply, format_success_reply
|
||||
@ -190,14 +192,14 @@ class AnkiConnect:
|
||||
|
||||
|
||||
def getModel(self, modelName):
|
||||
model = self.collection().models.byName(modelName)
|
||||
model = self.collection().models.by_name(modelName)
|
||||
if model is None:
|
||||
raise Exception('model was not found: {}'.format(modelName))
|
||||
return model
|
||||
|
||||
|
||||
def getField(self, model, fieldName):
|
||||
fieldMap = self.collection().models.fieldMap(model)
|
||||
fieldMap = self.collection().models.field_map(model)
|
||||
if fieldName not in fieldMap:
|
||||
raise Exception('field was not found in {}: {}'.format(model['name'], fieldName))
|
||||
return fieldMap[fieldName][1]
|
||||
@ -214,24 +216,19 @@ class AnkiConnect:
|
||||
self.window().requireReset()
|
||||
|
||||
|
||||
def stopEditing(self):
|
||||
if self.collection() is not None:
|
||||
self.window().maybeReset()
|
||||
|
||||
|
||||
def createNote(self, note):
|
||||
collection = self.collection()
|
||||
|
||||
model = collection.models.byName(note['modelName'])
|
||||
model = collection.models.by_name(note['modelName'])
|
||||
if model is None:
|
||||
raise Exception('model was not found: {}'.format(note['modelName']))
|
||||
|
||||
deck = collection.decks.byName(note['deckName'])
|
||||
deck = collection.decks.by_name(note['deckName'])
|
||||
if deck is None:
|
||||
raise Exception('deck was not found: {}'.format(note['deckName']))
|
||||
|
||||
ankiNote = anki.notes.Note(collection, model)
|
||||
ankiNote.model()['did'] = deck['id']
|
||||
ankiNote.note_type()['did'] = deck['id']
|
||||
if 'tags' in note:
|
||||
ankiNote.tags = note['tags']
|
||||
|
||||
@ -314,14 +311,14 @@ class AnkiConnect:
|
||||
val = note.fields[0]
|
||||
if not val.strip():
|
||||
return 1
|
||||
csum = anki.utils.fieldChecksum(val)
|
||||
csum = anki.utils.field_checksum(val)
|
||||
|
||||
# Create dictionary of deck ids
|
||||
dids = None
|
||||
if duplicateScope == 'deck':
|
||||
did = deck['id']
|
||||
if duplicateScopeDeckName is not None:
|
||||
deck2 = collection.decks.byName(duplicateScopeDeckName)
|
||||
deck2 = collection.decks.by_name(duplicateScopeDeckName)
|
||||
if deck2 is None:
|
||||
# Invalid deck, so cannot be duplicate
|
||||
return 0
|
||||
@ -362,13 +359,13 @@ class AnkiConnect:
|
||||
|
||||
def getCard(self, card_id: int) -> Card:
|
||||
try:
|
||||
return self.collection().getCard(card_id)
|
||||
return self.collection().get_card(card_id)
|
||||
except NotFoundError:
|
||||
self.raiseNotFoundError('Card was not found: {}'.format(card_id))
|
||||
|
||||
def getNote(self, note_id: int) -> Note:
|
||||
try:
|
||||
return self.collection().getNote(note_id)
|
||||
return self.collection().get_note(note_id)
|
||||
except NotFoundError:
|
||||
self.raiseNotFoundError('Note was not found: {}'.format(note_id))
|
||||
|
||||
@ -421,14 +418,20 @@ class AnkiConnect:
|
||||
msg.setText('"{}" requests permission to use Anki through AnkiConnect. Do you want to give it access?'.format(origin))
|
||||
msg.setInformativeText("By granting permission, you'll allow the website to modify your collection on your behalf, including the execution of destructive actions such as deck deletion.")
|
||||
msg.setWindowIcon(self.window().windowIcon())
|
||||
msg.setIcon(QMessageBox.Question)
|
||||
msg.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
|
||||
msg.setDefaultButton(QMessageBox.No)
|
||||
msg.setIcon(QMessageBox.Icon.Question)
|
||||
msg.setStandardButtons(QMessageBox.StandardButton.Yes|QMessageBox.StandardButton.No)
|
||||
msg.setDefaultButton(QMessageBox.StandardButton.No)
|
||||
msg.setCheckBox(QCheckBox(text='Ignore further requests from "{}"'.format(origin), parent=msg))
|
||||
msg.setWindowFlags(Qt.WindowStaysOnTopHint)
|
||||
pressedButton = msg.exec_()
|
||||
if hasattr(Qt, 'WindowStaysOnTopHint'):
|
||||
# Qt5
|
||||
WindowOnTopFlag = Qt.WindowStaysOnTopHint
|
||||
elif hasattr(Qt, 'WindowType') and hasattr(Qt.WindowType, 'WindowStaysOnTopHint'):
|
||||
# Qt6
|
||||
WindowOnTopFlag = Qt.WindowType.WindowStaysOnTopHint
|
||||
msg.setWindowFlags(WindowOnTopFlag)
|
||||
pressedButton = msg.exec()
|
||||
|
||||
if pressedButton == QMessageBox.Yes:
|
||||
if pressedButton == QMessageBox.StandardButton.Yes:
|
||||
config = aqt.mw.addonManager.getConfig(__name__)
|
||||
config["webCorsOriginList"] = util.setting('webCorsOriginList')
|
||||
config["webCorsOriginList"].append(origin)
|
||||
@ -440,7 +443,7 @@ class AnkiConnect:
|
||||
}
|
||||
|
||||
# if the origin isn't an empty string, the user clicks "No", and the ignore box is checked
|
||||
elif origin and pressedButton == QMessageBox.No and msg.checkBox().isChecked():
|
||||
elif origin and pressedButton == QMessageBox.StandardButton.No and msg.checkBox().isChecked():
|
||||
config = aqt.mw.addonManager.getConfig(__name__)
|
||||
config["ignoreOriginList"] = util.setting('ignoreOriginList')
|
||||
config["ignoreOriginList"].append(origin)
|
||||
@ -454,7 +457,10 @@ class AnkiConnect:
|
||||
@util.api()
|
||||
def getProfiles(self):
|
||||
return self.window().pm.profiles()
|
||||
|
||||
|
||||
@util.api()
|
||||
def getActiveProfile(self):
|
||||
return self.window().pm.name
|
||||
|
||||
@util.api()
|
||||
def loadProfile(self, name):
|
||||
@ -486,7 +492,15 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def sync(self):
|
||||
self.window().onSync()
|
||||
mw = self.window()
|
||||
auth = mw.pm.sync_auth()
|
||||
if not auth:
|
||||
raise Exception("sync: auth not configured")
|
||||
out = mw.col.sync_collection(auth, mw.pm.media_syncing_enabled())
|
||||
accepted_sync_statuses = [out.NO_CHANGES, out.NORMAL_SYNC]
|
||||
if out.required not in accepted_sync_statuses:
|
||||
raise Exception(f"Sync status {out.required} not one of {accepted_sync_statuses} - see SyncCollectionResponse.ChangesRequired for list of sync statuses: https://github.com/ankitects/anki/blob/e41c4573d789afe8b020fab5d9d1eede50c3fa3d/proto/anki/sync.proto#L57-L65")
|
||||
mw.onSync()
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -517,7 +531,7 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def deckNames(self):
|
||||
return self.decks().allNames()
|
||||
return [x.name for x in self.decks().all_names_and_ids()]
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -545,13 +559,8 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def createDeck(self, deck):
|
||||
try:
|
||||
self.startEditing()
|
||||
did = self.decks().id(deck)
|
||||
finally:
|
||||
self.stopEditing()
|
||||
|
||||
return did
|
||||
self.startEditing()
|
||||
return self.decks().id(deck)
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -559,7 +568,7 @@ class AnkiConnect:
|
||||
self.startEditing()
|
||||
|
||||
did = self.collection().decks.id(deck)
|
||||
mod = anki.utils.intTime()
|
||||
mod = anki.utils.int_time()
|
||||
usn = self.collection().usn()
|
||||
|
||||
# normal cards
|
||||
@ -569,7 +578,6 @@ class AnkiConnect:
|
||||
|
||||
# then move into new deck
|
||||
self.collection().db.execute('update cards set usn=?, mod=?, did=? where id in ' + scids, usn, mod, did)
|
||||
self.stopEditing()
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -583,14 +591,11 @@ class AnkiConnect:
|
||||
# this is dangerous, so let's raise our own exception
|
||||
raise Exception("Since Anki 2.1.28 it's not possible "
|
||||
"to delete decks without deleting cards as well")
|
||||
try:
|
||||
self.startEditing()
|
||||
decks = filter(lambda d: d in self.deckNames(), decks)
|
||||
for deck in decks:
|
||||
did = self.decks().id(deck)
|
||||
self.decks().rem(did, cardsToo=cardsToo)
|
||||
finally:
|
||||
self.stopEditing()
|
||||
self.startEditing()
|
||||
decks = filter(lambda d: d in self.deckNames(), decks)
|
||||
for deck in decks:
|
||||
did = self.decks().id(deck)
|
||||
self.decks().remove([did])
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -600,7 +605,7 @@ class AnkiConnect:
|
||||
|
||||
collection = self.collection()
|
||||
did = collection.decks.id(deck)
|
||||
return collection.decks.confForDid(did)
|
||||
return collection.decks.config_dict_for_deck_id(did)
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -608,13 +613,13 @@ class AnkiConnect:
|
||||
collection = self.collection()
|
||||
|
||||
config['id'] = str(config['id'])
|
||||
config['mod'] = anki.utils.intTime()
|
||||
config['mod'] = anki.utils.int_time()
|
||||
config['usn'] = collection.usn()
|
||||
if int(config['id']) not in [c['id'] for c in collection.decks.all_config()]:
|
||||
return False
|
||||
try:
|
||||
collection.decks.save(config)
|
||||
collection.decks.updateConf(config)
|
||||
collection.decks.update_config(config)
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
@ -648,8 +653,8 @@ class AnkiConnect:
|
||||
if configId not in [c['id'] for c in collection.decks.all_config()]:
|
||||
return False
|
||||
|
||||
config = collection.decks.getConf(configId)
|
||||
return collection.decks.confId(name, config)
|
||||
config = collection.decks.get_config(configId)
|
||||
return collection.decks.add_config_returning_id(name, config)
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -658,7 +663,7 @@ class AnkiConnect:
|
||||
if int(configId) not in [c['id'] for c in collection.decks.all_config()]:
|
||||
return False
|
||||
|
||||
collection.decks.remConf(configId)
|
||||
collection.decks.remove_config(configId)
|
||||
return True
|
||||
|
||||
@util.api()
|
||||
@ -722,10 +727,7 @@ class AnkiConnect:
|
||||
|
||||
@util.api()
|
||||
def deleteMediaFile(self, filename):
|
||||
try:
|
||||
self.media().syncDelete(filename)
|
||||
except AttributeError:
|
||||
self.media().trash_files([filename])
|
||||
self.media().trash_files([filename])
|
||||
|
||||
@util.api()
|
||||
def getMediaDirPath(self):
|
||||
@ -740,8 +742,6 @@ class AnkiConnect:
|
||||
nCardsAdded = collection.addNote(ankiNote)
|
||||
if nCardsAdded < 1:
|
||||
raise Exception('The field values you have provided would make an empty question on all cards.')
|
||||
collection.autosave()
|
||||
self.stopEditing()
|
||||
|
||||
return ankiNote.id
|
||||
|
||||
@ -799,6 +799,17 @@ class AnkiConnect:
|
||||
except:
|
||||
return False
|
||||
|
||||
@util.api()
|
||||
def canAddNoteWithErrorDetail(self, note):
|
||||
try:
|
||||
return {
|
||||
'canAdd': bool(self.createNote(note))
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
'canAdd': False,
|
||||
'error': str(e)
|
||||
}
|
||||
|
||||
@util.api()
|
||||
def updateNoteFields(self, note):
|
||||
@ -809,19 +820,9 @@ class AnkiConnect:
|
||||
if name in ankiNote:
|
||||
ankiNote[name] = value
|
||||
|
||||
audioObjectOrList = note.get('audio')
|
||||
self.addMedia(ankiNote, audioObjectOrList, util.MediaType.Audio)
|
||||
self.addMediaFromNote(ankiNote, note)
|
||||
|
||||
videoObjectOrList = note.get('video')
|
||||
self.addMedia(ankiNote, videoObjectOrList, util.MediaType.Video)
|
||||
|
||||
pictureObjectOrList = note.get('picture')
|
||||
self.addMedia(ankiNote, pictureObjectOrList, util.MediaType.Picture)
|
||||
|
||||
ankiNote.flush()
|
||||
|
||||
self.collection().autosave()
|
||||
self.stopEditing()
|
||||
self.collection().update_note(ankiNote, skip_undo_entry=True);
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -836,6 +837,57 @@ class AnkiConnect:
|
||||
if not updated:
|
||||
raise Exception('Must provide a "fields" or "tags" property.')
|
||||
|
||||
@util.api()
|
||||
def updateNoteModel(self, note):
|
||||
"""
|
||||
Update the model and fields of a given note.
|
||||
|
||||
:param note: A dictionary containing note details, including 'id', 'modelName', 'fields', and 'tags'.
|
||||
"""
|
||||
# Extract and validate the note ID
|
||||
note_id = note.get('id')
|
||||
if not note_id:
|
||||
raise ValueError("Note ID is required")
|
||||
|
||||
# Extract and validate the new model name
|
||||
new_model_name = note.get('modelName')
|
||||
if not new_model_name:
|
||||
raise ValueError("Model name is required")
|
||||
|
||||
# Extract and validate the new fields
|
||||
new_fields = note.get('fields')
|
||||
if not new_fields or not isinstance(new_fields, dict):
|
||||
raise ValueError("Fields must be provided as a dictionary")
|
||||
|
||||
# Extract the new tags
|
||||
new_tags = note.get('tags', [])
|
||||
|
||||
# Get the current note from the collection
|
||||
anki_note = self.getNote(note_id)
|
||||
|
||||
# Get the new model from the collection
|
||||
collection = self.collection()
|
||||
new_model = collection.models.by_name(new_model_name)
|
||||
if not new_model:
|
||||
raise ValueError(f"Model '{new_model_name}' not found")
|
||||
|
||||
# Update the note's model
|
||||
anki_note.mid = new_model['id']
|
||||
anki_note |