Fix up action list in Appendix A.
[ibg.git] / tables / wordtable.py
1 """
2 Convert word table to various other formats.
3
4 Needs tabulate (https://pypi.python.org/pypi/tabulate).
5
6 Usage: python wordtable.py actions.txt > actions.rst
7 """
8
9 import sys
10 from tabulate import tabulate
11
12
13 def tabledata(data, rows=10):
14     padding = rows - (len(data) % rows)
15     values = list(data) + [None] * padding
16     for row in range(rows):
17         yield [values[idx] for idx in range(row, len(values), rows)]
18
19
20 def writetable(words, formats):
21     table = list(tabledata(words))
22     print ".. Autogenerated by wordtable.py -- do not edit!"
23
24     for fmt in formats:
25         output = tabulate(table, tablefmt=fmt)
26
27         print
28         print ".. raw::", fmt
29         print
30         for line in output.split("\n"):
31             print "  ", line
32
33
34 if __name__ == "__main__":
35     import fileinput
36
37     words = []
38     for word in fileinput.input():
39         words.append(word.strip())
40
41     writetable(words, formats=['html', 'latex'])