Last active
August 29, 2015 14:05
-
-
Save mrmt/e663ece9e65702c36cc2 to your computer and use it in GitHub Desktop.
WordpressからexportしたWXRをMT形式に変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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