A space for CFD. Especially for ANSYS/CFX and ICEMCFD kiddosuper_in_simwe@hotmail.com(msn) 473063212(qq)

A perl script to change *.xml into *.html

上一篇 / 下一篇  2008-03-23 21:03:31 / 个人分类:Articles

If you use msn messenger in windows ,and use gaim/pidgin in Linux as well, you may  need this perl to handle your logs file into same format (*.html)SimWe个人空间*j~lim#O

`ws:y&bt"z~G0This is an efficient tool to maintain your logs file into unified format
&f ce Y k9p0good lucks and enjoy itSimWe个人空间z-@(}sq$['j*R9J
if you have problems about this perl , you may send me email to kiddosuper@gmail.com
l)@ gos9g|0SimWe个人空间[ WI1o0~.hX2JC
#!/usr/bin/perlSimWe个人空间8F-TC [q
##
+w$E'xFF$X0# Translator of MSN message log from msn-messenger 8.x to gaim(html)
p%yQ&I4yq3H0# author : Kiddosuper in www.simwe.comSimWe个人空间MF]wX/v+G!?#v#\
# this perl refers to a perl msn2gaim.pl which build by Yong-ling ChenSimWe个人空间-T x$^\cN
# I modify something, (change the date/time parse)SimWe个人空间[TF$z7_
# suggest you use Open PerlIDE to run this perl , easier and ok
U-_/`T&hpy{0# this file has been tested properlySimWe个人空间%KV6[%}(zP,k+H
# if you have problems,please contact me kiddosuper@gmail.comSimWe个人空间u A$HYy.A@DJ:K
# at line 118,you may change your desired contact name to mark different color
c,c&tc0Mpzd"u%P0##
Tfr3E+_i2ra u0use Time::Local;
D C&E#tXM0use File::Basename;
1i.H @dH)Y p0print "Traslate from msn messenger logs into html (gaim style)\n" ;
$oldDir = $ARGV[0];
ivRD qM~%pn{5L0if ( ! (-e $oldDir ) ) {
?6P%So?(Al0 print "usage: msn2html yourPath.\n" ;
)C"zSpftV`k0 print "   ex: msn2html D:\handle\n" ;
:L#L!N9|? A0 exit ;SimWe个人空间~(@uetR|G ^O
}
@"E Qs2V YP0chdir $oldDir;
while ($fn=<*.xml>){
(R_e"}*?^0~,e&E ?"M }0print "handling $fn.........\n";
YBW:k di$za:w0$fnbase=basename($fn,'.xml');
#build contacts messages directory
'ic#Yn H_(C0system("md $fnbase") if  ( ! (-e $fnbase) );
open (FH,$fn) ||die "cannot open $fn\n" ;
# Read all *.xml in that working directorySimWe个人空间'[5oBq/X\7uY&V
 #start create a temporary fileSimWe个人空间d` JbWZL
 open (OUT, ">$oldDir/$fnbase/$fnbase.txt") ;
d5` R:L8Wg+fD0  print "Handling  $oldDir/$fnbase/$fnbase.txt\n";
(eO9X,pZ Kx | r.d0 while (<FH>) {SimWe个人空间^&ANI/iM
  # delete  CR/LFSimWe个人空间{_~ ghj
  chomp ;
n%s0bKI)aZA.[tV0  # join every linesSimWe个人空间O^q;H/Df{
  $cont.= $_ ;
F Te2H%| N ]0B-@h0 }
SimWe个人空间~[xFd/i!X
 # get FirstSessionID & LastSessionID and count the splitted files numberSimWe个人空间!CL GUZ|'Qk
 ($FSID,$LSID)=($cont=~m!FirstSessionID="(\d+)" LastSessionID="(\d+)"!) ;
'\KXO$]3WP0A;L0 # delete unecesary head section files
X3Y-SNf:gt0 $cont=~s!<\?xml.*?\>(<Message.*)!\1! ;SimWe个人空间gg.P'G Yf^
 #delet the ^M markSimWe个人空间K+@/?$L#|pa1]2}0|m
 $cont=~s!!!g ;SimWe个人空间-hC(q,c!B
 #break into a new for for each messageSimWe个人空间f-lE/^1a
 $cont=~s!(</Message>)!\1\n!g ;
"{%^$?TI6l ~HO'IW0 #break into a new line for invitation
\*HT,e0m#QO-S c0 $cont=~s!(</Invitation>)!\1\n!g ;SimWe个人空间HtO%DJ @6`V1~
 #break into a new line for invitation response
1o?5i.H7w!qb#x2Va0 $cont=~s!(</InvitationResponse>)!\1\n!g ;SimWe个人空间Z'p0|O6x5y@![
 # break into a new line for every join
?[kPG%A0 $cont=~s!(</Join>)!\1\n!g ;
(f5nYxF!g }0  #modify some msn bugs which only show <TEXT>, not font family and color
{ W%k\4] DX0 $cont=~s!<Text>!<Text Style="font-family:Microsoft Sans Serif; color:#008080; ">!ig ;
 # write into temporary and close file
 print OUT $cont ;
#g-}9h7UtF#_3C4`T~0 close FN ;SimWe个人空间\J1r2YSUo Y5`yoA
 close OUT ;
t}6O#?-c4nV-Z0 # according to  session id ,split logs into individual file
8~9ZDw&a+q0 for $j ($FSID .. $LSID) {
C2x9{ASN"s C0   ($year, $mon, $day, $hour, $min, $sec)=SimWe个人空间8cN|d'|Y#x
  ($cont=~m#DateTime="(\d{4})-(\d{2})\-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*?SessionID="$j"#) ;SimWe个人空间pL~)HD
  # shift +8 hour for the timestamp
3El(Z&i&Gx,em0   if ($sec.$min.$hour ne ""){
l DH\ k0   my $time=timelocal($sec,   $min,   $hour,   $day,   $mon-1,   $year);
I]%I m(tQoU J0   $time+=28800;
/Pl@z:{FwMY)[0    ($sec,$min,$hour,$day,$mon,$year)=localtime($time);
&Qt"JQ(~0\ Z t"W0    $mon+=1;
iE ?6gd-S.D4m.G0    $year+=1900;SimWe个人空间'mX5L }/a"O
  # modify date
   $mon = "0".$mon if ( $mon < 10 ) ;
8y7I4H-@#{0  $day = "0".$day if ( $day < 10 ) ;
  $date= $year."-".$mon."-".$day ;SimWe个人空间#|6P6dIK6E/P {6S
   $hour ="0".$hour if ( $hour < 10 ) ;SimWe个人空间 f h6@B'E[$PQ
   $min = "0".$min if ( $min < 10 ) ;SimWe个人空间i JSCt'K(Ym
    $sec = "0".$sec if ( $sec < 10 ) ;
  $time = $hour.$min.$sec ;
)x `7\/i%JS)\ d5X*d0  $desc = "Conversation with $fnbase at $date "."$hour:$min:$sec";
2f Do)mnk]f0  # open a temporary fileSimWe个人空间4\$Z F*\ZWDW P
  open(FN, "$oldDir\\$fnbase\\$fnbase.txt") || die "$oldDir\\$fnbase\\$fnbase.txt not found\n" ;SimWe个人空间x%A3A"t5E R$EU
  # change filename into gaim file formatSimWe个人空间1l;AMnq+i,N0e
  $newFn = "$oldDir\\$fnbase\\$date.$time.html" ;
\"TYWdnr'e*g0  # skip when files are existed already
2Q W#?8`"wZ7O,q QB0  if (-e $newFn) {
aY.{0`5Oi0   print " --> existed\n" ;SimWe个人空间7C/ja{d$?
  }
f^'T7a3OH]0  else {
dGALVssU0      print "writing files: ".$newFn;SimWe个人空间*i7ct;D}#I3dcI
   print "\n" ;SimWe个人空间:c}N~.s}.u
   open(OUT, "> $newFn") ;
;jm3`4i\n5M5V1LpRg0   # html head section
9VJAu]b0   print OUT "<html><head>" ;SimWe个人空间h!D?9_+A&N,K~g
   print OUT "<meta. http-equiv=\"cont-type\"" ;
(k|LYB0X5{W0   print OUT " cont=\"text/html; charset=UTF-8\">" ;
8F f:J,|`y+z}0   print OUT "<title>$desc</title>" ;SimWe个人空间pUc+i.SJ7]
   print OUT "</head><body>" ;
0AtB!c#S0   print OUT "<h3>$desc</h3>\n" ;SimWe个人空间gSiSrUq
   # (main)change  M$-xml protocol into gaim-htmlprotocolSimWe个人空间"@%Wk N0?9Ww O
   while ( <FN> ) {SimWe个人空间[z6I6N1~
    # get same session idSimWe个人空间1v3V q+I,II#k
    ($tmp)=($_=~m!(.+SessionID="$j".+\n)!) ;SimWe个人空间}`J z@.B!hR7bu
    #get user
&^#|"c!FO$k7Kf0    ($usr)=($tmp=~m!<From>.*?="(.*?)"!) ;
U)Q ? h\;j/|(}-H8S0    # define user logs color
6Q#Yr@0m%rO0d.@c W0    $color1="#18569E";
2SI]w\0    $color2="#A82F2F";
P%r x.]U2v0    if ( $usr=~m/^pril.*/ ) {
*l5Q[(o uf(^1]2b0     $color = $color1 ;
-r3oT_-Q0    } else {
z4`7V)cvGb!n m0     $color = $color2 ;
Y#R%[HXu ~uP0    }SimWe个人空间t7e'C/aeS
    # translate message
,E%a'oXY z"k0    $tmp=~s!<Message.*?Time="(\S+) (\d+):(\d+):(\d+)".*?><From><User FriendlyName="(.*?)"/></From>.*?<Text Style="font-family:(.*?); color:(.*?); ">(.*?)</Text.*?</Message>\n!<font color="$color"><font size="2">(\1 \2:\3:\4:)</font> <b>\5:</b></font> <span style='font-family:\6; '><span style='color: \7; '>\8</span></span><br/>\n! ;
O3R_1n"od0    # translate other label
6pG&ha Uo7L0    $tmp=~s!^<(\S+)\s.*?Time="(\S+) (\d+):(\d+):(\d+)".*">(.*?)</Text></\1>$!<font size="2">(\2 \3:\4:\5)</font><b> \6</b><br/>! ;
5Q,{3j_ K ^0    print OUT $tmp ;SimWe个人空间7C4IY:r m7i4z
   }SimWe个人空间8hbUSL'A5U
   # htmlendding
R U4\U(B4xz0   print OUT "</body></html>\n" ;SimWe个人空间3W4R~J `
   close FN ;SimWe个人空间7S] v;p6L&Zv
   close OUT ;
;K1Cq'W@sUI0     }SimWe个人空间8i,|,z+T_p v!k'~
    }
U%]7HsOq0 }SimWe个人空间i'L-m.g-uZc$@*]p
 #clear  $cont contentsSimWe个人空间![}K(s3g
 $cont = "" ;SimWe个人空间!e/l u5YBd"bZ
 # clean temperoary file
%[:T#_7y YpSo0  unlink("$oldDir/$fnbase/$fnbase.txt") if (-e "$oldDir/$fnbase/$fnbase.txt") ;
}
 

8lI%m)Y:Y*W0 
You can go to http://kiddosuper.10gbfreehost.com/msn2html.rar to download this perl directly
 
or visit my website http://kiddosuper.10gbfreehost.com to view more stuffs

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 1516
  • 日志数: 30
  • 建立时间: 2007-03-19
  • 更新时间: 2008-03-23

RSS订阅

Open Toolbar