diff --git a/anki/importing/__init__.py b/anki/importing/__init__.py index ccec99873..d6dd7ed13 100644 --- a/anki/importing/__init__.py +++ b/anki/importing/__init__.py @@ -3,14 +3,15 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from anki.importing.csvfile import TextImporter +from anki.importing.apkg import AnkiPackageImporter from anki.importing.anki2 import Anki2Importer from anki.importing.anki1 import Anki1Importer from anki.importing.supermemo_xml import SupermemoXmlImporter from anki.lang import _ Importers = ( - (_("Text separated by tabs or semicolons (*.txt,*.csv)"), TextImporter), - (_("Anki 2.0 Collection (*.anki2)"), Anki2Importer), + (_("Text separated by tabs or semicolons (*)"), TextImporter), + (_("Packaged Anki Deck (*.apkg)"), AnkiPackageImporter), (_("Anki 1.2 Deck (*.anki)"), Anki1Importer), (_("Supermemo XML export (*.xml)"), SupermemoXmlImporter), ) diff --git a/anki/importing/apkg.py b/anki/importing/apkg.py new file mode 100644 index 000000000..af0bdd7fa --- /dev/null +++ b/anki/importing/apkg.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright: Damien Elmes +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import zipfile +from anki.utils import tmpfile +from anki.importing.anki2 import Anki2Importer + +class AnkiPackageImporter(Anki2Importer): + + def run(self): + # extract the deck from the zip file + z = zipfile.ZipFile(self.file) + f = z.open("collection.anki2") + colpath = tmpfile(suffix=".anki2") + open(colpath, "w").write(f.read()) + # pass it to the anki2 importer + self.file = colpath + Anki2Importer.run(self) diff --git a/anki/importing/base.py b/anki/importing/base.py index 6688e5339..8fd8a44a2 100644 --- a/anki/importing/base.py +++ b/anki/importing/base.py @@ -10,6 +10,7 @@ from anki.utils import intTime, maxID class Importer(object): needMapper = False + needDelimiter = False def __init__(self, col, file): self.file = file