-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgen_card.py
executable file
·51 lines (47 loc) · 1.6 KB
/
gen_card.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from teanglann import get_teanglann_definition
import argparse
import pystache
parser = argparse.ArgumentParser(
description="Lookup English definitions of Irish words from the wonderful "
"https://www.teanglann.ie/ and https://www.focloir.ie/")
arg = parser.add_argument
arg(
'-v', '--verbose',
help='List of matching words from foclóir '
'and full definition from teanglann',
action='store_true')
arg(
'irish-word',
help="Irish word to look up")
if __name__ == '__main__':
args = vars(parser.parse_args())
if args:
GA = args['irish-word']
PoS, EN, Gender = get_teanglann_definition(GA, verbose=args['verbose'])
renderer = pystache.Renderer()
front = renderer.render_path('anki-cards/front-template.html', {
'GA': GA,
})
# back includes front
back = renderer.render_path('anki-cards/back-template.html', {
'GA': GA,
'EN': EN,
'Part of Speech': PoS,
'Gender': Gender,
'FrontSide': '[FrontSide]'
})
# probably Pystache can do the foll. (raw html) but hacking it for now
entire = back.replace('[FrontSide]', front)
page = '<html>'
page += '<head>'
page += f'<title>{GA} - preview of Anki flashcard</title>'
page += f'<link type="text/css" src="style.css" />'
page += '</head>'
page += '<body>'
page += entire
page += '</body>'
page += '</html>'
with open(f'anki-cards/{GA}.html', 'w') as f:
f.write(page)