diff --git a/anki/importing/__init__.py b/anki/importing/__init__.py index a2259c592..4ac509448 100644 --- a/anki/importing/__init__.py +++ b/anki/importing/__init__.py @@ -8,6 +8,7 @@ from anki.importing.anki2 import Anki2Importer from anki.importing.anki1 import Anki1Importer from anki.importing.supermemo_xml import SupermemoXmlImporter from anki.importing.mnemo import MnemosyneImporter +from anki.importing.pauker import PaukerImporter from anki.lang import _ Importers = ( @@ -16,4 +17,5 @@ Importers = ( (_("Anki 1.2 Deck (*.anki)"), Anki1Importer), (_("Mnemosyne 2.0 Deck (*.db)"), MnemosyneImporter), (_("Supermemo XML export (*.xml)"), SupermemoXmlImporter), + (_("Pauker 1.8 Lesson (*.pau.gz)"), PaukerImporter), ) diff --git a/anki/importing/pauker.py b/anki/importing/pauker.py new file mode 100644 index 000000000..6bf22a1f3 --- /dev/null +++ b/anki/importing/pauker.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Copyright: Andreas Klauer +# License: BSD-3 + +import gzip, math, random +import xml.etree.ElementTree as ET +from anki.importing.noteimp import NoteImporter, ForeignNote, ForeignCard +from anki.stdmodels import addBasicModel + +class PaukerImporter(NoteImporter): + '''Import Pauker 1.8 Lesson (*.pau.gz)''' + + def fields(self): + '''Pauker is Front/Back''' + print "pauker", "fields", self + return 2 + + def foreignNotes(self): + '''Build and return a list of notes.''' + print "pauker", "foreignNotes", self + notes = [] + + try: + f = gzip.open(self.file) + tree = ET.parse(f) + lesson = tree.getroot() + assert lesson.tag == "Lesson" + finally: + f.close() + + index = -4 + ivlmax = -1 + + for batch in lesson.findall('./Batch'): + index += 1 + + if index >= 0: + ivlmin = ivlmax+1 + ivlmax = int(math.exp(index)) + + for card in batch.findall('./Card'): + front = card.findtext('./FrontSide/Text') + back = card.findtext('./ReverseSide/Text') + note = ForeignNote() + note.fields = [x.strip().replace('\n','
') for x in [front, back]] + note.tags.append("Pauker%+d" % (index,)) + notes.append(note) + + if index == -3: + # new cards + continue + + for tmpl in self.model['tmpls']: + fc = ForeignCard() + if index >= 0: + # due cards + fc.ivl = random.randint(ivlmin,ivlmax) + fc.due = self.col.sched.today+random.randint(ivlmin,ivlmax) + fc.factor = 2500 * fc.ivl / ivlmax + fc.reps = index * fc.ivl / ivlmax + else: + # shortterm cards + fc.ivl = 0 + fc.due = self.col.sched.today + fc.factor = random.randint(2000, 2500) + fc.reps = random.randint(0,3) + note.cards[tmpl['ord']] = fc + + return notes