Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Parses a Wordpress XML export file and imports the posts into Tumblr. See for info.
require "hpricot"
require "net/http"
require "uri"
TUMBLR_PASS = "thepasswordlol"
FILE_URLS_TO_TIDS = "old-new.txt"
ported_urls = File.readlines(FILE_URLS_TO_TIDS).collect {|l| l.strip.match(/^(.*);/)[1] }
doc = Hpricot("wordpress.2009-10-10.xml") )
(doc/"item").each do |item|
comments ="wp:comment_approved").reject {|ct| ct.inner_text != "1" }.size
pingbacks ="wp:comment_type").reject {|ct| ct.inner_text != "pingback" }.size
is_private = ("wp:status").first.inner_text == "private" )
has_comments = ( comments > 0 && comments > pingbacks )
tags ="category[@domain='tag']").collect(&:inner_text).uniq
next if"wp:post_type").first.inner_text != "post"
title ="title").first.inner_text
postdate ="wp:post_date").first.inner_text
link ="link").first.inner_text
# link = ORIGINAL_DOMAIN +"wp:post_date_gmt").first.inner_text[0, 10].gsub(/-/, "/") + "/" +"wp:post_name").first.inner_text + "/" # do this if the link is empty
next if ported_urls.include?(link)
content ="content:encoded").first.inner_text
# My WP blog was using Disqus. I'd like to retain the comments.
content += "\n\n<script type='text/javascript'>var disqus_url = '#{link}';</script>" if has_comments
next if content.strip.empty?
puts "- #{title} [#{comments}/#{pingbacks}]"
puts " #{link}"
response = Net::HTTP.post_form(
:email => TUMBLR_USER,
:password => TUMBLR_PASS,
:type => "regular",
:date => postdate,
:title => title,
:body => content,
:tags => tags.join(","),
:format => "markdown",
:group => TUMBLR_DOMAIN,
:private => is_private ? 1 : 0
tumblr_id = response.read_body, "a") do |f|
f.puts "#{link};#{tumblr_id}"

This comment has been minimized.

Copy link

@Jamesking56 Jamesking56 commented Feb 11, 2013

Do you have a version of this that works with API v2? Theres no scripts out there at all to export from WordPress to Tumblr so it'd be great if you could modify this to work with API v2! This script doesn't work anymore due to API v1 being shut down :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.