import string def printHTMLfile(body,title): ''' create a standard html page with titles, header etc. and add the body (an html box) to that page. File created is title+'.html' ''' fd = open(title+'.html','w') theStr=""" """+title+"""

"""+title+'

'+'\n'+body+'\n'+"""
""" fd.write(theStr) fd.close() def makeHTMLbox(body): ''' make an HTML box that has all the words in it ''' boxStr = """
%s
""" return boxStr % (body) def makeHTMLword(word,cnt,high,low): ''' make a word with a font size to be placed in the box. Font size is scaled between htmlBig and htmlLittle (to be user set). high and low represent the high and low counts in the document. cnt is the cnt of the word ''' htmlBig = 96 htmlLittle = 14 ratio = (cnt-low)/float(high-low) fontsize = htmlBig*ratio + (1-ratio)*htmlLittle fontsize = int(fontsize) wordStr = '%s ' return wordStr % (str(fontsize), word) # example usage pairs = [['hi',5],['there',6],['mom',10],['fred',2],['bill',20]] highCount=20 lowCount=2 body='' for word,cnt in pairs: body = body + makeHTMLword(word,cnt,highCount,lowCount) box = makeHTMLbox(body) printHTMLfile(box,'testFile')