020b1190e838c006ede3dcb3d2b9e6f5fea600c1
[librarian.git] / scripts / fn_qualifiers_list_from_redmine.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8
3
4 """
5 This scripts reads the table of footnote qualifiers from Redmine
6 and produces contents of fn_qualifiers.py – a list of valid qualifiers.
7 """
8
9 from lxml import etree
10 from urllib2 import urlopen
11
12 url = 'http://redmine.nowoczesnapolska.org.pl/projects/wl-publikacje/wiki/Lista_skr%C3%B3t%C3%B3w'
13
14 parser = etree.HTMLParser()
15 tree = etree.parse(urlopen(url), parser)
16
17 print """\
18 # -*- coding: utf-8
19 \"""
20 List of standard footnote qualifiers.
21 This file is generated by scripts/fn_qualifiers_list_from_wiki.py,
22 do not edit it.
23 \"""
24 from __future__ import unicode_literals
25
26
27 FN_QUALIFIERS = {""".encode('utf-8')
28
29 for td in tree.findall('//td'):
30     print ("    '%s': '%s'," % (
31         td[0].text.replace('\\', '\\\\').replace("'", "\\'"),
32         td[0].tail.strip(' -').replace('\\', '\\\\').replace("'", "\\'")
33     )).encode('utf-8')
34
35 print """    }""".encode('utf-8')