-
Notifications
You must be signed in to change notification settings - Fork 0
/
quote.py
64 lines (54 loc) · 1.67 KB
/
quote.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
from ui import *
import re
class Quote:
def __init__(self):
self.quote = None
self.source = None
self.extra = None
def input(self):
self.quote = uinput(text='Quote:', required=True,
example="Life is [suffering]")
self.source = uinput(text='Source:', example='[Buddha] via [Pali Canon]')
self.extra = uinput(text='Pronunciation/mnemonics?', example='pah-lee',
allow_images=True)
def output(self):
print_accent('\n*** Card ***')
print(self.quote)
if self.source:
print(' - ' + self.source)
if self.extra:
print_hr()
print(self.extra)
summarize_images()
print()
def save(self, x):
m = x.models.byName('Cloze+details')
x.decks.current()['mid'] = m['id']
n = x.newNote()
i = 0
n['Text'] = self._to_anki()
combined_details = ''
html = images_save_htmlify(x)
if html:
combined_details += html
if self.extra:
combined_details += self.extra
if combined_details != '':
n['Extra'] = combined_details
x.addNote(n)
x.save()
print_loud('Card saved!', nl=2)
def name(self):
return '[ ]'
def _to_anki(self):
i = 0
def rfn(m):
nonlocal i
i += 1
return '{{c' + str(i) + '::'
text = self.quote
if self.source:
text += '<br><br>- ' + self.source
text = re.sub('\\[', rfn, text)
text = re.sub('\\]', '}}', text)
return text