I figured it was time to suffer through another blog migration and moved everything over to Posterous. This probably wasn't important at all, since I don't think I have the pre-2001 entries around anywhere, and the ones since then are pretty much narcissistic omphaloskepsis. But, it gave me an opportunity to prune out many of the semi-offensive posts and migrate to an easier posting platform. I haven't been updating mainly because I'm lazy. Twitter is really the top of my level of effort right now.
Posterous doesn't expose the same sort of migration assistant that it does for Tumblr and friends. Since the email interface does not appear to give control over the post dates, I had to use the API.
The first part of the problem involved pulling the data from Drupal. I un-published the posts I was embarrassed by, or posts that were just pointless to migrate. Then I pulled it all out of the db with 'echo "select node.title, created, body from node, node_revisions where node.nid = node_revisions.nid and status = 1"| mysql -u [username] -p[password] [database] > posterous_migration.txt'
I pulled the header row off (there's probably a flag to avoid emitting it in the first place, but I'm lazy.) and wrote a quick Ruby script to post the content to Posterous with the proper dates.
#!/usr/bin/env ruby
require 'net/http'
url=URI.parse(url)
r = File.open("posterous_migration.txt").readlines()
r.each {|line|
title = line.split(/\t/)[0]
raw_date = line.split(/\t/)[1]
body = line.split(/\t/)[2].chomp
new_body = body.gsub("\"", "\\\\\"") new_body = body.gsub("\\n", "<br>") new_date = Time.at(Integer(raw_date)).ctime params = {"body" => "#{new_body}", 'autopost' => '0', 'date' => "#{new_date}", 'title' => "#{title}"}
req = Net::HTTP::Post.new(url.path)
req.set_form_data(params)
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
}
And that was pretty much that. I had some missing images due to using relative paths while originally composing them in Drupal, but that was easily resolved. I also have some funky formatting, probably due to my nasty gsubs that I had there for an early attempt at passing all the information to curl.
Comments [0]