author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 15 Sep 2016 19:58:01 +0300 | |
changeset 556 | 78bf1097106a |
parent 555 | 4a3188fc8951 |
child 559 | 2b03300f610c |
permissions | -rw-r--r-- |
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
3 |
import os |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
import io |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
5 |
import sys |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
import codecs |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
import tempfile |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
import shutil |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
9 |
import signal |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
10 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
import gadict |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
FINAME = None |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
FONAME = None |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
if len(sys.argv) >= 2: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
FINAME = sys.argv[1] |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
if len(sys.argv) >= 3: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
FONAME = sys.argv[2] |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
LANGS = None |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
21 |
if len(sys.argv) >= 4: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
LANGS = set(sys.argv[3].split(",")) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
25 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
26 |
PARSER = gadict.Parser() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
27 |
try: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
28 |
DOM = PARSER.parse(FIN) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
29 |
except gadict.ParseException as ex: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
30 |
sys.stdout.write("{:s}{:s}\n".format(FINAME, repr(ex))) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
31 |
if __debug__: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
32 |
import traceback |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
33 |
traceback.print_exc() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
34 |
exit(1) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
35 |
finally: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
36 |
FIN.close() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
37 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
38 |
def cleanup(collection, tmpdir): |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
39 |
if collection: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
40 |
collection.close() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
41 |
if tmpdir: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
42 |
shutil.rmtree(tmpdir, ignore_errors=True) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
43 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
44 |
# signal.signal(signal.SIGINT, lambda signal, frame: cleanup()) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
45 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
46 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
47 |
if FONAME is None: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
48 |
raise Exception('Missing output file name') |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
49 |
# Looks like anki libs change working directory to media directory of current deck |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
50 |
# Therefore absolute path should be stored before creating temporary deck |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
51 |
FONAME = os.path.abspath(FONAME) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
52 |
FBASENAME, _ = os.path.splitext(os.path.basename(FONAME)) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
53 |
TMPDIR = tempfile.mkdtemp(dir = os.path.dirname(FONAME)) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
54 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
55 |
import hashlib |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
56 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
57 |
import anki |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
58 |
from anki.exporting import AnkiPackageExporter |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
59 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
60 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
61 |
class AnkiDbBuilder: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
62 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
63 |
def __init__(self, tmpdir, name): |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
64 |
self.tmpdir = tmpdir |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
65 |
self.name = name |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
66 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
67 |
self.collection = collection = anki.Collection(os.path.join(self.tmpdir, 'collection.anki2')) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
68 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
69 |
deck_id = collection.decks.id(self.name + "_deck") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
70 |
deck = collection.decks.get(deck_id) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
71 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
72 |
model = collection.models.new(self.name + "_model") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
73 |
model['tags'].append(self.name + "_tag") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
74 |
model['did'] = deck_id |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
75 |
model['css'] = """ |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
76 |
.card { |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
77 |
font-family: arial; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
78 |
font-size: 20px; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
79 |
text-align: center; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
80 |
color: black; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
81 |
background-color: white; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
82 |
} |
556
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
83 |
.ask { |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
84 |
margin-bottom: 1.2em; |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
85 |
} |
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
86 |
span.headword { |
556
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
87 |
font-weight: bolt; |
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
88 |
} |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
89 |
.pron { |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
90 |
color: magenta; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
91 |
} |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
92 |
.pos { |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
93 |
color: green; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
94 |
font-style: italic; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
95 |
} |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
96 |
.lang { |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
97 |
color: red; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
98 |
font-style: italic; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
99 |
} |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
100 |
.ant { |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
101 |
color: red; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
102 |
} |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
103 |
.syn { |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
104 |
color: blue; |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
105 |
} |
556
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
106 |
.attrs { |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
107 |
color: blue; |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
108 |
} |
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
109 |
""" |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
110 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
111 |
collection.models.addField(model, collection.models.newField('From')) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
112 |
collection.models.addField(model, collection.models.newField('To')) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
113 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
114 |
tmpl = collection.models.newTemplate('From -> To') |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
115 |
tmpl['qfmt'] = '<div class="from">{{From}}</div>' |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
116 |
tmpl['afmt'] = '{{FrontSide}}\n\n<hr id=answer>\n\n<div class="to">{{To}}</div>' |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
117 |
collection.models.addTemplate(model, tmpl) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
118 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
119 |
# Equivalent of: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
120 |
# collection.models.add(model) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
121 |
# without setting auto-generated ID. It is essential to keep model['id'] |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
122 |
# unchanged between upgrades or notes will be skipped!! |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
123 |
model['id'] = int(hashlib.sha1(self.name).hexdigest(), 16) % (2**63) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
124 |
collection.models.update(model) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
125 |
collection.models.setCurrent(model) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
126 |
collection.models.save(model) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
127 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
128 |
def guid(self, type_, headword): |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
129 |
""" |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
130 |
:type_ used to generate different notes from same headword |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
131 |
""" |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
132 |
h = hashlib.md5(":".join((self.name, type_, headword))) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
133 |
return h.hexdigest() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
134 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
135 |
def add_note(self, type_, id_, from_, to_): |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
136 |
note = self.collection.newNote() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
137 |
note['From'] = from_ |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
138 |
# print(from_) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
139 |
note['To'] = to_ |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
140 |
# print(to_) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
141 |
note.guid = self.guid(type_, id_) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
142 |
self.collection.addNote(note) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
143 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
144 |
def export(self, fname): |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
145 |
export = AnkiPackageExporter(self.collection) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
146 |
export.exportInto(fname) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
147 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
148 |
def close(self): |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
149 |
self.collection.close() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
150 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
151 |
try: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
152 |
builder = AnkiDbBuilder(TMPDIR, FBASENAME) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
153 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
154 |
for (headwords, translations) in DOM[1:]: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
155 |
identity = headwords[0].headword |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
156 |
buf = [] |
556
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
157 |
v1, v2, v3 = (None, None, None) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
158 |
singular, plural = (None, None) |
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
159 |
for hw in headwords: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
160 |
buf.append("<div clsas='headword'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
161 |
buf.append("<span clsas='headword'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
162 |
buf.append(hw.headword) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
163 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
164 |
if hw.pron is not None: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
165 |
buf.append(" <span class='pron'>[") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
166 |
buf.append(hw.pron) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
167 |
buf.append("]</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
168 |
if len(hw.attrs) > 0: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
169 |
l = [u"«"+x+u"»" for x in hw.attrs] |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
170 |
l.sort() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
171 |
buf.append("<span class='attrs'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
172 |
buf.append(", ".join(l)) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
173 |
buf.append("</span>") |
556
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
174 |
if 'v1' in hw.attrs: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
175 |
v1 = (hw.headword, hw.pron) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
176 |
if 'v2' in hw.attrs: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
177 |
v2 = (hw.headword, hw.pron) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
178 |
if 'v3' in hw.attrs: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
179 |
v3 = (hw.headword, hw.pron) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
180 |
if 's' in hw.attrs: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
181 |
singular = (hw.headword, hw.pron) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
182 |
if 'pl' in hw.attrs: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
183 |
plural = (hw.headword, hw.pron) |
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
184 |
buf.append("</div>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
185 |
direct_from = "".join(buf) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
186 |
buf = [] |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
187 |
for sense in translations: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
188 |
buf.append("<div class='sense'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
189 |
if sense.pos: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
190 |
buf.append("<span class='pos'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
191 |
buf.append(sense.pos) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
192 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
193 |
if sense.ant_list and len(sense.ant_list) > 0: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
194 |
buf.append("<span class='ant'>ant: ") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
195 |
buf.append("; ".join(["{"+s+"}" for s in sense.ant_list])) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
196 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
197 |
if sense.syn_list and len(sense.syn_list) > 0: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
198 |
buf.append("<span class='syn'>syn: ") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
199 |
buf.append("; ".join(["{"+s+"}" for s in sense.syn_list])) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
200 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
201 |
if len(sense.tr_list) > 1: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
202 |
for (lang, tr) in sense.tr_list: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
203 |
buf.append("<div class='sense'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
204 |
buf.append(" <span class='lang'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
205 |
buf.append(lang) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
206 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
207 |
buf.append(" <span class='tr'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
208 |
buf.append(tr) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
209 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
210 |
buf.append("</div>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
211 |
else: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
212 |
for (lang, tr) in sense.tr_list: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
213 |
buf.append(" <span class='lang'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
214 |
buf.append(lang) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
215 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
216 |
buf.append(" <span class='tr'>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
217 |
buf.append(tr) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
218 |
buf.append("</span>") |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
219 |
direct_to = "".join(buf) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
220 |
builder.add_note("en->tr", identity, direct_from, direct_to) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
221 |
builder.add_note("tr->en", identity, direct_to, direct_from) |
556
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
222 |
if v1 and v2 and v3: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
223 |
question = u"<div class='ask'>Find irregular verb:</div>" |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
224 |
riddle1 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v1</span>".format(v1[0], v1[1]) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
225 |
riddle2 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v2</span>".format(v2[0], v2[1]) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
226 |
riddle3 = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>v3</span>".format(v3[0], v3[1]) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
227 |
answer = u"{}<br>{}<br>{}<br>{}".format(riddle1, riddle2, riddle3, direct_to) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
228 |
builder.add_note("irregular1", identity, question + riddle1, answer) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
229 |
builder.add_note("irregular2", identity, question + riddle2, answer) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
230 |
builder.add_note("irregular3", identity, question + riddle3, answer) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
231 |
if singular and plural: |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
232 |
question = u"<div class='ask'>Find plural:</div>" |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
233 |
riddle_s = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>s</span>".format(singular[0], singular[1]) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
234 |
riddle_pl = u"<span class='headword'>{}</span> <span class='pron'>[{}]</span> <span class='attrs'>pl</span>".format(plural[0], plural[1]) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
235 |
answer = u"{}<br>{}<br>{}".format(riddle_s, riddle_pl, direct_to) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
236 |
builder.add_note("singular", identity, question + riddle_s, answer) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
237 |
builder.add_note("plural", identity, question + riddle_pl, answer) |
78bf1097106a
Add question for plural form and irregular verbs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
555
diff
changeset
|
238 |
|
555
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
239 |
|
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
240 |
builder.export(FONAME) |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
241 |
finally: |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
242 |
builder.close() |
4a3188fc8951
Generating Packaged Anki Desk files for Anki space repetition software.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
243 |
shutil.rmtree(TMPDIR, ignore_errors=True) |