parent
955b749aac
commit
9ba5c08c96
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.pyc
|
||||
AnkiConnect.zip
|
||||
meta.json
|
||||
.idea/
|
||||
|
30
README.md
30
README.md
@ -20,6 +20,7 @@ with the latest stable (2.1.x) releases of Anki; older versions (2.0.x and below
|
||||
* [Cards](https://foosoft.net/projects/anki-connect/#cards)
|
||||
* [Media](https://foosoft.net/projects/anki-connect/#media)
|
||||
* [Graphical](https://foosoft.net/projects/anki-connect/#graphical)
|
||||
* [Export](https://foosoft.net/projects/anki-connect/#export)
|
||||
|
||||
## Installation ##
|
||||
|
||||
@ -1866,3 +1867,32 @@ guarantee that your application continues to function properly in the future.
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
### Export ###
|
||||
|
||||
* **exportPackage**
|
||||
|
||||
Exports a given deck in .apkg format. Returns `true` if successful or `false` otherwise.
|
||||
The optional property `includeSched` (default is `false`) can be specified to include the
|
||||
cards' scheduling data.
|
||||
|
||||
*Sample request*:
|
||||
```json
|
||||
{
|
||||
"action": "exportPackage",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"deck": "Default",
|
||||
"path": "/data/Deck.apkg",
|
||||
"includeSched": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*Sample result*:
|
||||
```json
|
||||
{
|
||||
"result": true,
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
@ -29,8 +29,11 @@ from PyQt5.QtCore import QTimer
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
import anki
|
||||
import anki.exporting
|
||||
import anki.lang
|
||||
import anki.storage
|
||||
import aqt
|
||||
from anki.exporting import AnkiPackageExporter
|
||||
|
||||
from . import web, util
|
||||
|
||||
@ -1198,6 +1201,27 @@ class AnkiConnect:
|
||||
return results
|
||||
|
||||
|
||||
@util.api()
|
||||
def exportPackage(self, deck, path, includeSched=False):
|
||||
results = []
|
||||
results.append(self.createPackage(deck, path, includeSched))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def createPackage(self, deck, path, includeSched):
|
||||
collection = self.collection()
|
||||
if collection is not None:
|
||||
deck = collection.decks.byName(deck)
|
||||
if deck is not None:
|
||||
exporter = AnkiPackageExporter(collection)
|
||||
exporter.did = deck["id"]
|
||||
exporter.includeSched = includeSched
|
||||
exporter.exportInto(path)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Entry
|
||||
#
|
||||
|
21
tests/test_export.py
Executable file
21
tests/test_export.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import util
|
||||
|
||||
|
||||
class TestExport(unittest.TestCase):
|
||||
def runTest(self):
|
||||
fd, newname = tempfile.mkstemp(prefix="testexport", suffix=".apkg")
|
||||
os.close(fd)
|
||||
os.unlink(newname)
|
||||
success = util.invoke('exportPackage', deck='Default', path=newname)
|
||||
self.assertTrue(success)
|
||||
self.assertTrue(os.path.exists(newname))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user