#!/home/falling/bin/python import pathfix pathfix.fixPath() import string import cgi import HtmlTable FILENAME = 'diary-l.txt' def main(): print "Content-type: text/html\n\n" printHeader() form = cgi.FieldStorage() sortby = 1 if form.has_key('sort'): sortby = eval(form['sort'].value) sections = { 'a':{}, 'b':{}, 'c':{}, 'd':{}, 'e':{}, 'f':{}, 'g':{}, 'h':{}, 'i':{}, 'j':{}, 'k':{}, 'l':{}, 'm':{}, 'n':{}, 'o':{}, 'p':{}, 'q':{}, 'r':{}, 's':{}, 't':{}, 'u':{}, 'v':{}, 'w':{}, 'x':{}, 'y':{}, 'z':{}} ignore = ['the', 'an', 'a'] for line in open(FILENAME, 'r').readlines(): line = string.strip(line) if line != '': line = string.split(line, '|') for x in xrange(len(line)): line[x] = string.strip(line[x]) _t = string.lower(line[sortby]) fLet = 'z' #for x in xrange(len(_t)): # if _t[x] in string.letters: # fLet = _t[x] # break # Find the first character pos = 1 for x in range(len(_t)): if _t[x] in string.letters: pos = x break # Get rid of anything at the front _b = _t[pos:] _b = string.split(_b) for word in _b: if word not in ignore and word[0] in string.letters: fLet = word[0] break sections[fLet][_t] = line tbl = HtmlTable.HtmlTable(width='90%') tbl.addRow() keys = sections.keys() keys.sort() for key in keys: d = '' if sections[key] != {}: d = d + '' d = d + \ '' + \ string.upper(key) + \ '' if sections[key] != {}: d = d + '' tbl.addData(d, align='center', valign='top') tbl.endRow() print '

Comments and corrections go to Angie@falling.com. Enjoy!