Mercurial > hg > lxmldump
comparison lxmldump.py @ 35:5aafa87dbec2
Some Anki-related stuff, not finalized and thus hidden.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 25 May 2021 13:28:24 +0300 |
parents | 73f2f98e3eef |
children | 4c8aafff8c5f |
comparison
equal
deleted
inserted
replaced
34:73f2f98e3eef | 35:5aafa87dbec2 |
---|---|
26 ### | 26 ### |
27 # Operation modes | 27 # Operation modes |
28 PKK_MODE_NORMAL = 0 | 28 PKK_MODE_NORMAL = 0 |
29 PKK_MODE_DUMP = 1 | 29 PKK_MODE_DUMP = 1 |
30 PKK_MODE_XML = 2 | 30 PKK_MODE_XML = 2 |
31 PKK_MODE_ANKI = 3 | |
31 | 32 |
32 | 33 |
33 pkk_modes_list = { | 34 pkk_modes_list = { |
34 PKK_MODE_NORMAL: "normal", | 35 PKK_MODE_NORMAL: "normal", |
35 PKK_MODE_DUMP: "dump", | 36 PKK_MODE_DUMP: "dump", |
36 PKK_MODE_XML: "xml", | 37 PKK_MODE_XML: "xml", |
38 # PKK_MODE_ANKI: "anki", | |
37 } | 39 } |
38 | 40 |
39 | 41 |
40 # Default Ptr URL format strings | 42 # Default Ptr URL format strings |
41 pkk_ptr_url_fmt = { | 43 pkk_ptr_url_fmt = { |
42 PKK_MODE_NORMAL: u"<PTR:{href}>{text}</PTR>", | 44 PKK_MODE_NORMAL: u"<PTR:{href}>{text}</PTR>", |
45 PKK_MODE_ANKI: u"<a href='https://kaino.kotus.fi/cgi-bin/kks/karjala.cgi?a={href}'>{text}</a>", | |
43 } | 46 } |
44 | 47 |
45 | 48 |
46 # Element annotation mappings | 49 # Element annotation mappings |
47 pkk_element_annotation_map = { | 50 pkk_element_annotation_map = { |
48 "Fragment" : { | 51 "Fragment" : { |
49 PKK_MODE_NORMAL: ["<", ">"], | 52 PKK_MODE_NORMAL: ["<", ">"], |
53 PKK_MODE_ANKI: ["<", ">"], | |
50 }, | 54 }, |
51 } | 55 } |
52 | 56 |
53 | 57 |
54 # List of words in kks1/ useful for debugging, option -p | 58 # List of words in kks1/ useful for debugging, option -p |
272 optparser.add_argument("-x", "--xml", | 276 optparser.add_argument("-x", "--xml", |
273 dest="mode", | 277 dest="mode", |
274 action="store_const", const=PKK_MODE_XML, | 278 action="store_const", const=PKK_MODE_XML, |
275 help="output as XML") | 279 help="output as XML") |
276 | 280 |
281 optparser.add_argument("-A", "--anki", | |
282 dest="mode", | |
283 action="store_const", const=PKK_MODE_ANKI, | |
284 help=argparse.SUPPRESS) | |
285 # help="output Anki compatible") | |
286 | |
277 optparser.add_argument("--ptr-url-fmt", | 287 optparser.add_argument("--ptr-url-fmt", |
278 dest="ptr_url_fmt", | 288 dest="ptr_url_fmt", |
279 type=str, | 289 type=str, |
280 default=None, | 290 default=None, |
281 metavar="str", | 291 metavar="str", |
295 optparser.add_argument("-a", "--annotate", | 305 optparser.add_argument("-a", "--annotate", |
296 dest="annotate", | 306 dest="annotate", |
297 action="store_true", | 307 action="store_true", |
298 help="annotate strings") | 308 help="annotate strings") |
299 | 309 |
300 optparser.add_argument("-p", "--debug", | |
301 dest="debug", | |
302 action="store_true", | |
303 help=argparse.SUPPRESS) | |
304 | |
305 optparser.add_argument("-i", "--indent", | 310 optparser.add_argument("-i", "--indent", |
306 dest="indent", | 311 dest="indent", |
307 type=int, choices=range(0, 32), default=4, | 312 type=int, choices=range(0, 32), default=4, |
308 metavar="n", | 313 metavar="n", |
309 help='indent output by <n> characters (default: %(default)s)') | 314 help='indent output by <n> characters (default: %(default)s)') |
315 | |
316 optparser.add_argument("-p", "--debug", | |
317 dest="debug", | |
318 action="store_true", | |
319 help=argparse.SUPPRESS) | |
310 | 320 |
311 | 321 |
312 ### Show help if needed | 322 ### Show help if needed |
313 pkk_cfg = optparser.parse_args() | 323 pkk_cfg = optparser.parse_args() |
314 if len(pkk_cfg.filenames) == 0 or pkk_cfg.show_help: | 324 if len(pkk_cfg.filenames) == 0 or pkk_cfg.show_help: |
337 for dnode in xroot.findall("./DictionaryEntry"): | 347 for dnode in xroot.findall("./DictionaryEntry"): |
338 | 348 |
339 if pkk_cfg.debug and dnode.attrib["identifier"] not in pkk_debug_list: | 349 if pkk_cfg.debug and dnode.attrib["identifier"] not in pkk_debug_list: |
340 continue | 350 continue |
341 | 351 |
342 if pkk_cfg.mode == PKK_MODE_NORMAL: | 352 if pkk_cfg.mode in [PKK_MODE_NORMAL, PKK_MODE_ANKI]: |
343 try: | 353 try: |
344 pkk_output_node(0, dnode) | 354 pkk_output_node(0, dnode) |
345 except Exception as e: | 355 except Exception as e: |
346 pkk_dump_recursive(0, dnode) | 356 pkk_dump_recursive(0, dnode) |
347 print(str(e)) | 357 print(str(e)) |