agaskar.com

May 10 2009

Importing your Drupal blog posts to Tumblr with Ruby

You’ll need the mysql and tumblr gems. Comments and tags are thrown to the four winds.

require 'rubygems'
require 'mysql'
require 'tumblr'

def create_post(row)
  post(:type => 'regular',
          :title => row['title'],
          :body => row['body'],
          :date => Time.at(row['created'].to_i).localtime
  )
end
connection = Mysql.new('YOUR_MYSQL_SERVER', 'YOUR_MYSQL_USER', 'YOUR_MYSQL_PASS', 'YOUR_DRUPAL_TABLE')
result = connection.query('select * from node JOIN node_revisions nr ON (node.vid = nr.vid) where type = \'blog\' and status=1;')
Tumblr::API.write('YOUR_TUMBLR_EMAIL', 'YOUR_TUMBLR_PASSWORD') do
  result.each_hash {|row| create_post(row)}
end

Comments (View)
Page 1 of 1
blog comments powered by Disqus