Skip to content

Instantly share code, notes, and snippets.

@mrmt

mrmt/wxr2mt

Last active Aug 29, 2015
Embed
What would you like to do?
WordpressからexportしたWXRをMT形式に変換
#!/usr/bin/perl
use XML::Simple;
use Date::Parse;
use strict;
use warnings;
use feature 'say';
binmode(STDOUT, ':utf8');
my $xml = new XML::Simple;
my $data = $xml->XMLin($ARGV[0]);
for(my $n=0; $n<@{$data->{channel}->{item}}; $n++){
my $item = $data->{channel}->{item}[$n];
say 'TITLE: ', $item->{title};
say 'STATUS: publish';
say 'CONVERT BREAKS: __default__';
{
my $category = 'diary';
if(ref $item->{category} eq 'HASH'){
say 'CATEGORY: ', $item->{category}->{nicename};
}elsif(ref $item->{category} eq 'ARRAY'){
for(my $n=0; $n<@{$item->{category}}; $n++){
say 'CATEGORY: ', $item->{category}[$n]->{nicename};
}
}
}
{
my($ss,$mm,$hh,$day,$month,$year) = strptime($item->{pubDate}, 0);
my $ampm;
if($hh < 12){
$ampm = 'AM';
}else{
$ampm = 'PM';
$hh -= 12;
}
printf("DATE: %02d/%02d/%04d %02d:%02d:%02d %s\n",
$month+1, $day, $year+1900, $hh, $mm, $ss, $ampm);
}
say '-----';
say 'BODY:';
say $item->{'content:encoded'};
say '';
say '-----';
say 'EXTENDED BODY:';
say '';
say '-----';
say 'EXCERPT:';
say '';
say '-----';
say 'KEYWORDS:';
say '';
say '-----';
say '';
say '--------';
say '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.