My old shell scripts that have been retired from my dotfiles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.6 KiB

  1. #!/usr/bin/perl
  2. # dumpmsn - Pretty up MSN Messenger chat logs.
  3. #
  4. # Usage: dumpmsn *.xml
  5. #
  6. # This will create a folder named "html" and put the files there. Give it chat
  7. # logs from Windows Live Messenger 2011 or similar (no guarantees it
  8. # will work with other versions).
  9. #
  10. # --Kirsle
  11. # http://sh.kirsle.net/
  12. use 5.14.0;
  13. use strict;
  14. use warnings;
  15. use XML::Simple;
  16. if (!-d "html") {
  17. mkdir("html") or die "Can't create folder 'html': $@";
  18. }
  19. foreach my $file (@ARGV) {
  20. say "Dumping $file...";
  21. my $xml = XMLin($file, ForceArray => 1);
  22. my $html = $file;
  23. $html =~ s/\.xml$//g;
  24. open (my $fh, ">:utf8", "./html/$html.html");
  25. print {$fh} <<EOF;
  26. <!DOCTYPE html>
  27. <html>
  28. <head>
  29. <title>Conversation Log</title>
  30. <style>
  31. body {
  32. background-color: #FFFFFF;
  33. font-family: Verdana,Arial,Helvetica,sans-serif;
  34. font-size: small;
  35. color: #000000;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. EOF
  41. if (ref($xml->{Message}) ne "ARRAY") {
  42. warn "Not an array for $file";
  43. next;
  44. }
  45. foreach my $Message (@{$xml->{Message}}) {
  46. my $to = $Message->{To}->[0]->{User}->[0]->{FriendlyName};
  47. my $from = $Message->{From}->[0]->{User}->[0]->{FriendlyName};
  48. my $time = $Message->{Date} . " " . $Message->{Time};
  49. my ($text,$style);
  50. if (ref($Message->{Text}->[0])) {
  51. $text = $Message->{Text}->[0]->{content};
  52. $style = $Message->{Text}->[0]->{Style};
  53. } else {
  54. $text = $Message->{Text}->[0];
  55. }
  56. $style //= "";
  57. $style = " style=\"$style\"" if length $style > 0;
  58. print {$fh} "<strong>$time</strong><br>\n"
  59. . "<em>$from says:</em>\n"
  60. . "<blockquote$style>$text</blockquote>\n"
  61. . "<hr>\n\n";
  62. }
  63. print {$fh} "</body>\n</html>";
  64. close($fh);
  65. }