Created
March 26, 2011 01:18
-
-
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
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
#!/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