X-Git-Url: https://jxself.org/git/?p=ibg.git;a=blobdiff_plain;f=tables%2Fwordtable.py;fp=tables%2Fwordtable.py;h=b034b70009a5fd42627bf45051ca6c939a0bcf10;hp=0000000000000000000000000000000000000000;hb=dc7fec99d92b670126e1e73e05df8f60706edc2d;hpb=7042413e580a0709340a1bd04130d7a277b2c882 diff --git a/tables/wordtable.py b/tables/wordtable.py new file mode 100644 index 0000000..b034b70 --- /dev/null +++ b/tables/wordtable.py @@ -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'])