3 #Copyright (C) 2008 Luar Roji
5 #This program is free software; you can redistribute it and/or
6 #modify it under the terms of the GNU General Public License
7 #as published by the Free Software Foundation; either version 2
8 #of the License, or (at your option) any later version.
10 #This program is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with this program; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #For full license view COPYRIGHT file or go to:
20 #http://www.fsf.org/licensing/licenses/info/GPLv2.html
22 from datetime
import *
25 print "CenterIM Log2HTML - $Rev: 25$"
26 print "Luar Roji - http://roji.net\n"
29 print "Usage: " + sys
.argv
[0] + " [logFileName] {outFileName}"
31 print " If outFileName is not specified, logFileName+.html is assumed."
41 outfile
.write(s
+ "\n")
44 def outtd(msg
, field
):
46 if (field
=="timestamp1" or field
=="timestamp2"):
48 floatData
= float(data
)
49 dateTimeObj
= datetime
.fromtimestamp(floatData
)
50 data
= dateTimeObj
.strftime(DATEFORMAT
)
51 out(" <td class=\""+field
+"\">"+data
+"</td>")
56 DATEFORMAT
= "%d/%b/%Y %H:%M:%S"
57 now
= datetime
.now().strftime(DATEFORMAT
)
58 HTMLHEADER
= "<html>\n" + \
60 " <title>CenterIM Conversation</title>\n" + \
61 " <style type=\"text/css\">\n" + \
62 " tr.imparOUT { background-color: #BAF0FA; }\n" + \
63 " tr.parOUT { background-color: #F0BAFA; }\n" + \
64 " tr.imparIN { background-color: #BAF000; }\n" + \
65 " tr.parIN { background-color: #F0BA00; }\n" + \
66 " td.timestamp1 { width:11%; font-size: 80%; }\n" + \
69 " <!-- Generated by $Id$ on " +now
+ " -->\n" + \
71 " <table border=\"1\">"
73 HTMLFOOTER
= " </table>\n" + \
80 infilename
= sys
.argv
[1]
82 outfilename
= sys
.argv
[2]
84 outfilename
= infilename
+ ".html"
86 print "Opening input file..",
87 infile
= open(infilename
,"r")
89 print "Opening output file..",
90 outfile
= open(outfilename
,"w")
97 lineCount
= lineCount
+1
98 if (lineCount
%500==0):
99 print str(lineCount
) + " lines readed"
103 msg
= {'direction' : getLine(infile
),
104 'type' : getLine(infile
),
105 'timestamp1' : getLine(infile
),
106 'timestamp2' : getLine(infile
),
107 'message' : getLine(infile
)}
110 print "File reading done. " + str(lineCount
) +" lines readed."
111 print "Generating HTML output..",
115 if (msg
["type"]!="MSG"):
123 out(" <tr class=\""+trClass
+msg
["direction"]+"\">")
124 outtd(msg
,"timestamp1")
125 # outtd(msg,"timestamp2") -- Don't understand the difference between those
126 outtd(msg
,"direction")
127 # outtd(msg,"type") -- Redundant with the above if