#!/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 '
' print tbl.getText() tbl = HtmlTable.HtmlTable(width='90%') for key in keys: if sections[key] != {}: tbl.addRow() tbl.addData('', valign='bottom', colspan=3, height=10) tbl.endRow() tbl.addRow() l = '[ '+string.upper(key)+' ]' tbl.addData(l, colspan=3, align='center') tbl.endRow() tbl.addRow() tbl.addData('', colspan=3, height=10) tbl.endRow() tbl.addRow() iTbl = HtmlTable.HtmlTable(width='100%', border=1, bgcolor="#DCDCDC") iTbl.addRow() ekeys = sections[key].keys() ekeys.sort() for x in xrange(len(ekeys)): if x % 3 == 0: iTbl.endRow() iTbl.addRow() iTbl.addData('', colspan=3, height=15) iTbl.endRow() iTbl.addRow() entry = sections[key][ekeys[x]] name = entry[0] if string.find(name, ',') != -1: name = string.split(name, ',') name = '%s %s' % (name[1], name[0]) e = '' if sortby == 1: e = '' + \ '' + \ entry[1] + '
' + \ name + '
' + \ '
' else: e = '' + \ '' + \ name + '
' + \ entry[1] + '
' + \ '
' iTbl.addData(e, width='33%', align='center', valign='middle') iTbl.endRow() tbl.addData(iTbl.getText(), align='center') tbl.endRow() print tbl.getText() tbl = HtmlTable.HtmlTable(width='90%') tbl.addRow() tbl.addData('', height=15) tbl.endRow() tbl.addRow() 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 tbl.getText() print '
' printFooter() def printHeader(): print """ Diary-L Contributors

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

Sort by Author Sort by Title

""" def printFooter(): print """
Sort by Author Sort by Title

Click here to see Diary-L's Favorite Journals/Diaries.
Visit Xanadu (the author's website)
Visit "From the Heart" (the author's journal)

Last Update: April 2000
""" if __name__ == '__main__': main()