#!/usr/bin/perl
# Radio2Blosxom
# Author: Sam Ruby
<
rubys@apache.org>
# Version: 0+1i
# Home:
http://intertwingly.net/stories/2002/08/11/radio2blosxom.html
# Usage:
#
#   From Radio Tools->Developers->Quick
Script:
#
#      file.writeWholeFile(
"c:\\exportedWeblog.xml",
#                           
table.tableToXml( radio.weblog.init() ) )
#
#   From the blosxom $datadir:
#
#      perl radio2blosxom.pl
exportedWeblog.xml
use XML::Parser;
use HTTP::Date;
$p = new XML::Parser(Handlers => {Start =>
&handle_start,
                                 
Char  => &handle_char,
                                 
End   => &handle_end});
$p->parsefile($ARGV[0]) || die;
@context = ();
sub handle_start {
  my ($expat, $tag, %attr) = @_;
  push @context, $attr{name} || $tag;
  $title = $attr{value} if $tag eq 'string' and $attr{name} eq
'title';
  $data = "";
}
sub handle_char {
  $data .= @_[1];
}
sub handle_end {
  $tag = pop @context;
  return if $context[1] ne "posts";
  $timestamp = str2time($data) if $tag eq
"dateCreated";
  $body=$data if $tag eq "body";
  if ($#context == 1) {
    $tag =~ s/^0*//;
    open BLOG, ">$tag.txt";
    print BLOG "$title\n$body";
    close BLOG;
    utime $timestamp, $timestamp, "$tag.txt";
    $title = "";
  }
}