perl script for converting atom to MT import format
Ideally, this should probably be a plugin that uses the MT API, but this little bit of kludgery seems to do the trick. Be forewarned, I used a lot of perl modules that may be non-standard.
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use XML::XPath;
use XML::XPath::XMLParser;
use DateTime;
use DateTime::Format::ISO8601;
my $atomfeed_location = "atom.xml"; # CHANGE THIS TO THE PATH OF THE SOURCE FILE
my $author = "YOUR_NAME";
my $atom_xml = XML::XPath->new(filename=>$atomfeed_location);
my $atomnodeset = $atom_xml->find('/feed/entry');
foreach my $context ($atomnodeset->get_nodelist) {
print "AUTHOR: $author\n"
print "TITLE: ", $context->find('./title')->string_value, "\n";
my $url = $context->find('./link/@href')->string_value;
print "BASENAME: ", basename($url), "\n";
print "STATUS: Publish\n";
print "ALLOW COMMENTS: 1\n";
print "CONVERT BREAKS: 0\n";
print "ALLOW PINGS: 1\n";
my $pub_atom = $context->find('./published')->string_value;
my $pub_iso8601 = DateTime::Format::ISO8601->parse_datetime($pub_atom);
my $pub_mtif = $pub_iso8601->mdy('/') . ' ' . $pub_iso8601->hms;
print "DATE: ", $pub_mtif, "\n";
my $cat_list = $context->find('./category');
my $taglist = '';
foreach my $cat ($cat_list->get_nodelist) {
my $tag = $cat->find('./@term')->string_value();
$taglist = ($taglist eq '' ? $tag : $taglist . ',' . $tag);
}
print "TAGS: ", $taglist, "\n";
print "—--\n";
print "BODY:\n", $context->find('./content')->string_value, "\n", "—--\n";
print "——--\n";
}
Redirect the output of this script to a file, and import the file into MT, and you should be all set. As you can see, there is no recourse for handling comments or trackbacks. Note also that categories are imported as tags!