RSS import to WordPress

I have fixed the date part of my script and tidied it up a bit so that you can pass in the file and the status you want the posts to come in as on the command line. Run it like this, rss_feed.xml draft

Ironically looking at the documentation WordPress does have a feature to import from RSS feeds. I’m guessing that it’s not included as part of their free hosted service because they don’t want spam blogs to have an easy source of input.


use strict;
use XML::Simple;

my $file = shift;
	print "Usage $0 rss_feed.xml [draft|publish]\n";
my $xs = XML::Simple->new();
my $rss_feed = $xs->XMLin($file);
my $status = shift;
	$status = "draft";
my $items = $rss_feed->{channel}->{item};

# I set this as being above the last ID of the posts already on my blog
# I'm not sure if it matters.
my $num = 50; 
my @months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; 
foreach my $item (@$items)
	$item->{link} =~ /.*\/(.*?)$/;
	my $name = $1;
	$item->{pubDate} =~ /(\d\d) (\w\w\w) (\d\d\d\d) (\d\d:\d\d:\d\d) /;
	my $mon = 1;
	my $mon_name = $2;
	while($months[$mon-1] ne $mon_name)
	my $wp_date = sprintf "%4.4d-%2.2d-%2.2d %s", $3, $mon, $1, $4;
print << "END";
<guid isPermaLink="false"></guid>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s