Created
March 15, 2010 03:03
-
-
Save toland/332449 to your computer and use it in GitHub Desktop.
Script to import Wordpress content into Tumblr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'net/http' | |
require 'nokogiri' | |
TUMBLR_USER = '[email protected]' | |
TUMBLR_PASS = 'yourpassword' | |
url = URI.parse('http://www.tumblr.com/api/write') | |
# Read the WP export file | |
counter = 0 | |
doc = Nokogiri::XML(File.read("wordpress.xml")) | |
doc.xpath('//item').each do |item| | |
status = item.at_xpath('wp:status').text | |
title = item.at_xpath('title').text | |
if %w(publish draft).include?(status) | |
puts "publishing item #{title}..." | |
counter += 1 | |
res = Net::HTTP.post_form(url, { | |
'email' => TUMBLR_USER, | |
'password' => TUMBLR_PASS, | |
'type' => 'regular', | |
'format' => 'markdown', | |
'title' => title, | |
'date' => item.at_xpath('wp:post_date').text, | |
'slug' => item.at_xpath('wp:post_name').text, | |
'body' => item.at_xpath('content:encoded').text.gsub(/<!--more-->/, ''), | |
'tags' => item.xpath('category[@nicename]').map(&:text).join(','), | |
'state' => (status == 'publish') ? 'published' : 'draft' | |
}) | |
puts res.body | |
sleep(1) | |
if counter % 5 == 0 | |
# sleep for a longer amount of time every 5 items | |
sleep(30) | |
end | |
else | |
puts "Ignoring item #{title}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment