#!/usr/bin/env python import sys def parse(f): data = [] buff = open(f).read() for items in buff.split(':'): # check items x = items.find('(') li = [] if x > -1: for p_items in items[x+1:-1].split(','): # the key k = p_items.strip()[1] # the text for the option li.append((k, ''.join([i for i in p_items if i != '[' and i != ']']).strip())) data.append((items.strip().split()[0],li)) # no options else: if items.strip(): data.append((items.strip(),[])) return data def generate_html(data): html = '\n
\n\n\n\n' return html if __name__ == '__main__': print generate_html(parse(sys.argv[1]))