#!/usr/bin/python #Copyright (C) 2008 Luar Roji #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #of the License, or (at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # #For full license view COPYRIGHT file or go to: #http://www.fsf.org/licensing/licenses/info/GPLv2.html from datetime import * import sys print "CenterIM Log2HTML - $Rev: 25$" print "Luar Roji - http://roji.net\n" def usage(): print "Usage: " + sys.argv[0] + " [logFileName] {outFileName}" print "" print " If outFileName is not specified, logFileName+.html is assumed." print "" sys.exit() def getLine(f): s = f.readline() s = s.rstrip('\n\r') return s def out(s): outfile.write(s + "\n") # print s def outtd(msg, field): data = msg[field] if (field=="timestamp1" or field=="timestamp2"): if (data!=""): floatData = float(data) dateTimeObj = datetime.fromtimestamp(floatData) data = dateTimeObj.strftime(DATEFORMAT) out(" "+data+"") msglist = [] x=0 DATEFORMAT = "%d/%b/%Y %H:%M:%S" now = datetime.now().strftime(DATEFORMAT) HTMLHEADER = "\n" + \ " \n" + \ " CenterIM Conversation\n" + \ " \n" + \ " \n" + \ " \n" + \ " \n" + \ " " HTMLFOOTER = "
\n" + \ " \n" + \ "\n" if len(sys.argv)<2: usage() infilename = sys.argv[1] if len(sys.argv)>2: outfilename = sys.argv[2] else: outfilename = infilename + ".html" print "Opening input file..", infile = open(infilename,"r") print "Ok" print "Opening output file..", outfile = open(outfilename,"w") print "Ok" print "Processing..." lineCount = 0 while infile: s = infile.readline() lineCount = lineCount+1 if (lineCount%500==0): print str(lineCount) + " lines readed" if (len(s)==0): break; if (s=="\x0c\n"): msg = {'direction' : getLine(infile), 'type' : getLine(infile), 'timestamp1' : getLine(infile), 'timestamp2' : getLine(infile), 'message' : getLine(infile)} msglist.append(msg) print "File reading done. " + str(lineCount) +" lines readed." print "Generating HTML output..", out(HTMLHEADER) for msg in msglist: if (msg["type"]!="MSG"): continue x=x+1 if (x%2==0): trClass = "par" else: trClass = "impar" out(" ") outtd(msg,"timestamp1") # outtd(msg,"timestamp2") -- Don't understand the difference between those outtd(msg,"direction") # outtd(msg,"type") -- Redundant with the above if outtd(msg,"message") out(" ") out(HTMLFOOTER) print "Done." infile.close() outfile.close()