Created
March 10, 2011 02:41
-
-
Save henare/863476 to your computer and use it in GitHub Desktop.
Imports a MediaWiki XML export into a Gollum wiki
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 | |
require 'rubygems' | |
require 'hpricot' | |
require 'gollum' | |
wiki = Gollum::Wiki.new('openaustralia.wiki') | |
file = File.open("OpenAustralia-20110309232515.xml", "r") | |
doc = Hpricot(file) | |
doc.search('/mediawiki/page').each do |el| | |
title = el.at('title').inner_text | |
content = el.at('text').inner_text | |
commit = { :message => "Import MediaWiki page #{title} into Gollum", | |
:name => 'Henare Degan', | |
:email => 'henare.degan@gmail.com' } | |
begin | |
puts "Writing page #{title}" | |
wiki.write_page(title, :mediawiki, content, commit) | |
rescue Gollum::DuplicatePageError => e | |
p "Duplicate #{title}" | |
end | |
end | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice! I had to add
require 'gollum-lib'