Skip to content

Instantly share code, notes, and snippets.

@rzhw
Created March 26, 2011 01:18
Show Gist options
  • Save rzhw/887935 to your computer and use it in GitHub Desktop.
Save rzhw/887935 to your computer and use it in GitHub Desktop.
Creates a CSV for DISQUS' migration tool for cases where the root directory name is different, but the permalinks are the same
#!/usr/bin/env ruby
# Written by Richard Z.H. Wang, based on wordpressxml2jekyll.rb
require 'rubygems'
require 'hpricot'
require 'clothred'
require 'time'
require 'yaml'
require 'fileutils'
require 'uri'
WORDPRESS_XML_FILE_PATH = File.join(File.dirname(__FILE__), "/wordpress.xml")
OLD_PREFIX = 'http://rewrite.name/wp/'
NEW_PREFIX = 'http://blog.rewrite.name/'
file = File.open(WORDPRESS_XML_FILE_PATH, "rb");
contents = file.read
# Hpricot will destroy <link> contents as it expecting a <link href="">
# so we change link to link2 and Hpricot will leave it alone.
contents.gsub!(/link>/, "link2>")
doc = Hpricot(contents)
File.open(File.join(File.dirname(__FILE__), "map.csv"), "w") { |f| }
(doc / "item").each do |item|
next unless item.search("wp:status").first.inner_text == "publish"
File.open(File.join(File.dirname(__FILE__), "map.csv"), "a") do |file|
file.write item.at("link2").inner_text + "," + item.at("link2").inner_text.gsub(OLD_PREFIX, NEW_PREFIX) + "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment