/
QA.py
86 lines (67 loc) · 1.72 KB
/
QA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from ..helper.formatHelper import list2str
from ..note import Note
from ..model import Model
from ..config import dict as conf
from ..config import config_updater
from ..log import notetype_logger as log
notetype_name = "QA"
if notetype_name not in conf["notetype"]:
conf["notetype"][notetype_name] = {}
settings = conf["notetype"][notetype_name]
priority = None
def update_qa_config():
global settings, priority
priority = settings.get("priority", 10)
config_updater.append((update_qa_config, 10))
def check(lines: list, extra_params={}) -> bool:
return len(lines) >= 2
def get(text: str, deck: str, tags: list, extra_params={}) -> Note:
lines = text.splitlines()
front = lines[0]
back = list2str(lines[1:], '', '\n')
if front == "":
log.info("Blank front text, skipping.")
return
if back == "":
log.info("Blank back text, skipping.")
return
return QANote(front=front, back=back, deck=deck, tags=tags)
BACK = r"""{{FrontSide}}
<hr id=answer>
{{Back}}"""
CSS = r""".card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
ul {
display: inline-block;
text-align: left;
}
ol {
display: inline-block;
text-align: left;
}
"""
MODELNAME = "AnkiLink-Basic"
MODELID = 1145141921
_model = Model(
modelId=MODELID,
modelName=MODELNAME,
fields=["Front", "Back"],
templates=[
{
'Name': 'Card 1',
'Front': '{{Front}}',
'Back': BACK
}
],
css=CSS
)
class QANote(Note):
def __init__(self, front, back, deck, tags):
global _model
super().__init__(model=_model, fields={
"Front": front, "Back": back}, deck=deck, tags=tags)