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.

68 lines
1.7 KiB

  1. #!/usr/bin/perl
  2. # dumpsms - Dump the SMS logs saved by "SMS Backup & Restore" into friendly
  3. # readable HTML files!
  4. #
  5. # Usage: dumpsms <sms-dump.xml>
  6. # Ex: dumpsms sms-20120629202942.xml
  7. #
  8. # It will create a folder "./sms" if it doesn't exist, and output all the logs
  9. # into that folder. It saves HTML files after the contact name, if available.
  10. # Logs are opened in append mode, so if you run the script multiple times the
  11. # logs get appended to the end of the file!
  12. #
  13. # --Kirsle
  14. # http://sh.kirsle.net/
  15. use 5.14.0;
  16. use strict;
  17. use warnings;
  18. use autodie;
  19. use XML::Simple;
  20. my $xml = shift or die "$0 <*.xml>";
  21. mkdir("sms") unless -d "sms";
  22. my $ref = XMLin($xml);
  23. foreach my $sms (@{$ref->{sms}}) {
  24. my $num = $sms->{address};
  25. my $color = $sms->{type} eq "1" ? "receive" : "send";
  26. my $dir = $sms->{type} eq "1" ? "From" : "Sent to";
  27. my $file = "./sms/$sms->{contact_name}.html";
  28. if (!-f $file) {
  29. open (my $fh, ">", $file);
  30. print {$fh} "<!DOCTYPE html>\n"
  31. . "<html>\n"
  32. . "<head>\n"
  33. . "<title>Conversation with $sms->{contact_name}</title>\n"
  34. . "<style>\n"
  35. . "body {\n"
  36. . " font-family: Verdana,Arial,sans-serif;\n"
  37. . " font-size: small;\n"
  38. . " color: #000000;\n"
  39. . "}\n"
  40. . ".receive {\n"
  41. . " color: #0000FF;\n"
  42. . "}\n"
  43. . ".send {\n"
  44. . " color: #FF0000;\n"
  45. . "}\n"
  46. . "</style>\n"
  47. . "</head>\n"
  48. . "<body>\n\n";
  49. close($fh);
  50. }
  51. open (my $fh, ">>:utf8", "./sms/$sms->{contact_name}.html");
  52. print {$fh} "<strong class='$color'>$sms->{readable_date}</strong><br>\n"
  53. . "<strong>$dir</strong> $sms->{contact_name} - $num\n"
  54. . "<blockquote>$sms->{body}</blockquote>\n"
  55. . "<hr>\n";
  56. close($fh);
  57. }
  58. say "Wrote logs to ./sms";