from readability import readabilitytests log_file = open('./final.log') words_dict = {} count_dict = {} # rip the logs apart and build a list of what each nick has said for line in log_file: # ignore the first 16 characters, as that's the date stamp #print line[10:] spoken_line = line[11:] if line[11:].startswith('<') else None if spoken_line: nick = spoken_line[1:spoken_line.find('>')] # this is a system message, ignore it if nick == "***": continue if count_dict.get(nick): count_dict[nick] += 1 else: count_dict[nick] = 1 # add a full stop, otherwise the analysis gets a bit confused words = spoken_line[spoken_line.find('>') +2:] +"." if words_dict.get(nick): words_dict[nick] += words else: words_dict[nick] = words count_first_list = [] nick_first_list = [] # build some nice lists of how much people have said for k in count_dict: nick_first_list.append((k,count_dict[k])) count_first_list.append((count_dict[k], k)) # sort these out so we can use them later nick_first_list = sorted(nick_first_list) count_first_list = sorted(count_first_list) output_file = open('./output.html', 'w') output_file.write("#isotoma analysis") output_file.write("") for count in reversed(count_first_list): output_file.write("") output_file.write("") output_file.write("") output_file.write("
" + str(count[0]) + "" + count[1] +"
") for nick in count_dict.keys(): output_file.write("

" + nick + "

") textengine = readabilitytests.ReadabilityTool() textengine.lang = "eng" results = textengine.getReportAll(words_dict[nick]) output_file.write("") for testname in textengine.analyzedVars: output_file.write("") if testname == "words": continue output_file.write("") output_file.write("") output_file.write("
" + testname + ": " + str(textengine.analyzedVars[testname]) + "
") for testname in results.keys(): output_file.write("") output_file.write("") output_file.write("") output_file.write("") output_file.close()
" + testname + ": " + str(round(results[testname](words_dict[nick]), 2)) + "