scripts/dumpmsn

75 lines
1.6 KiB
Perl
Executable File

#!/usr/bin/perl
# dumpmsn - Pretty up MSN Messenger chat logs.
#
# Usage: dumpmsn *.xml
#
# This will create a folder named "html" and put the files there. Give it chat
# logs from Windows Live Messenger 2011 or similar (no guarantees it
# will work with other versions).
#
# --Kirsle
# http://sh.kirsle.net/
use 5.14.0;
use strict;
use warnings;
use XML::Simple;
if (!-d "html") {
mkdir("html") or die "Can't create folder 'html': $@";
}
foreach my $file (@ARGV) {
say "Dumping $file...";
my $xml = XMLin($file, ForceArray => 1);
my $html = $file;
$html =~ s/\.xml$//g;
open (my $fh, ">:utf8", "./html/$html.html");
print {$fh} <<EOF;
<!DOCTYPE html>
<html>
<head>
<title>Conversation Log</title>
<style>
body {
background-color: #FFFFFF;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: small;
color: #000000;
}
</style>
</head>
<body>
EOF
if (ref($xml->{Message}) ne "ARRAY") {
warn "Not an array for $file";
next;
}
foreach my $Message (@{$xml->{Message}}) {
my $to = $Message->{To}->[0]->{User}->[0]->{FriendlyName};
my $from = $Message->{From}->[0]->{User}->[0]->{FriendlyName};
my $time = $Message->{Date} . " " . $Message->{Time};
my ($text,$style);
if (ref($Message->{Text}->[0])) {
$text = $Message->{Text}->[0]->{content};
$style = $Message->{Text}->[0]->{Style};
} else {
$text = $Message->{Text}->[0];
}
$style //= "";
$style = " style=\"$style\"" if length $style > 0;
print {$fh} "<strong>$time</strong><br>\n"
. "<em>$from says:</em>\n"
. "<blockquote$style>$text</blockquote>\n"
. "<hr>\n\n";
}
print {$fh} "</body>\n</html>";
close($fh);
}