#!/usr/bin/env python3
# vim: fileencoding=utf-8 ft=python et sw=4 ts=4 sts=4 tw=79
import os
def main():
line_dict = {}
with open('diceware_wordlist_cz.txt', 'rt', encoding='utf8') as f:
# f.read(3) # skip BOM
for num, word in (l.rstrip('\n').split(None, 1) for l in f):
pre = num[:-1]
if pre in line_dict:
line_dict[pre].append(word)
else:
line_dict[pre] = [word]
with open('diceware_table_nice.txt.new', 'wt', encoding='utf8') as f:
for num, words in sorted(line_dict.items()):
f.write('%s%sX: %s\n' % (
'¯' if num.endswith('11') else (
'_' if num.endswith('6') else ' '
),
num,
' | '.join(word.ljust(6) for word in words)
))
os.rename('diceware_table_nice.txt.new', 'diceware_table_nice.txt')
if __name__ == '__main__':
main()