First I grabbed some code from Marcus Crafter that I found after many many Google searches. Since that didn't really do what I needed, but was a really good start, I hacked it up to use the ruby-blogger client library. It saved me a TON of work. I did have to apply this small patch:
Then I ended up with this script:--- client.rb (revision 24)
+++ client.rb (working copy)
@@ -147,6 +147,7 @@
xmlFragment.instruct!
xmlFragment.tag!("entry","xmlns"=>"http://www.w3.org/2005/Atom","xmlns:app"=>'http://purl.org/atom/app#') do | doc |
doc.title(@title,:type=>'text')
+ doc.published(@published)
doc.content(@content,:type=>'html')
doc.tag!("author") do | author |
author.email @author_email
@@ -242,7 +243,7 @@
#if no links are specified, then return an error!
if links.nil?
- raise ArgumentError "links parameter is required!"
+ raise ArgumentError("links parameter is required!")
end
#look for the 'service.post' value
Several constants have to be set at the start of the script. Then it should go through and pull the posts out of your old blog and dump them into blogger. It does assume the old blog used Textile for formating and converts every post body to html. Also it doesn't migrate any comments or post tags. Maybe I will get to that later. Thanks to this handy page, I have a nice way to syntax highlight the code.#!/usr/bin/env ruby
#
# Migrate from a MetaWeblog enabled blog to blogger
#
require 'xmlrpc/client'
require 'rexml/document'
require 'rexml/xpath'
require 'time'
require 'rubygems'
require 'RedCloth'
# Checkout http://code.google.com/p/ruby-blogger/ and point to it here
require '/Users/kelp/checkouts/ruby-blogger/lib/client.rb'
# Find this in the of your blogger page source
POST_URI = 'http://www.blogger.com/feeds//posts/default '
EMAIL = 'username@gmail.com'
PASSWORD= 'password'
# What ever user name you post as on blogger
USER = 'username'
OLD_BLOG_URL = "http://example.com/"
OLD_BLOG_URI = "/rpc/"
OLD_BLOG_USER = 'username'
OLD_BLOG_PASS = 'password'
OLD_BLOG_ID = blogid
# Number of posts to migrate
POSTS = number of posts
class Blog
def initialize(host, path, username, password, blog_id = 1, port = 80)
@server = XMLRPC::Client.new(host, path, port)
@blog_id = blog_id
@username = username
@password = password
end
def posts(count = 5)
puts "Getting Posts"
@server.call('metaWeblog.getRecentPosts', @blog_id, @username, @password, count)
end
end
# These should be: old blog URL, old blog URI, old blog username, old blog password, old blog id
oldblog = Blog.new(OLD_BLOG_URL, OLD_BLOG_URI, OLD_BLOG_USER, OLD_BLOG_PASS, OLD_BLOG_ID)
# replace 135 with the number of posts you intend to migrate
oldblog.posts(POSTS).reverse.each_with_index do |post, index|
blogger_post = GData::Post.new
puts "#{index}: migrating post: #{post['title']}"
puts ""
time = post["dateCreated"].to_time
blogger_post.published = Time.parse(time.to_s).xmlschema
blogger_post.title = post["title"]
body = RedCloth.new(post["description"]).to_html
blogger_post.body = body
blogger_post.author_name = USER
blogger_post.author_email = EMAIL
GData::Client.logger.level = Logger::DEBUG
client = GData::Client.new(EMAIL,PASSWORD,{"service.post"=>POST_URI})
client.save(blogger_post)
end