Fix up action list in Appendix A.
[ibg.git] / tables / wordtable.py
diff --git a/tables/wordtable.py b/tables/wordtable.py
new file mode 100644 (file)
index 0000000..b034b70
--- /dev/null
@@ -0,0 +1,41 @@
+"""
+Convert word table to various other formats.
+
+Needs tabulate (https://pypi.python.org/pypi/tabulate).
+
+Usage: python wordtable.py actions.txt > actions.rst
+"""
+
+import sys
+from tabulate import tabulate
+
+
+def tabledata(data, rows=10):
+    padding = rows - (len(data) % rows)
+    values = list(data) + [None] * padding
+    for row in range(rows):
+        yield [values[idx] for idx in range(row, len(values), rows)]
+
+
+def writetable(words, formats):
+    table = list(tabledata(words))
+    print ".. Autogenerated by wordtable.py -- do not edit!"
+
+    for fmt in formats:
+        output = tabulate(table, tablefmt=fmt)
+
+        print
+        print ".. raw::", fmt
+        print
+        for line in output.split("\n"):
+            print "  ", line
+
+
+if __name__ == "__main__":
+    import fileinput
+
+    words = []
+    for word in fileinput.input():
+        words.append(word.strip())
+
+    writetable(words, formats=['html', 'latex'])