Skip to content

Instantly share code, notes, and snippets.

@bfroehle
Forked from henare/mw-to-gollum.rb
Last active December 10, 2015 22:08
Show Gist options
  • Save bfroehle/4499750 to your computer and use it in GitHub Desktop.
Save bfroehle/4499750 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
import requests
html = requests.get('http://wiki.ipython.org/Special:AllPages')
all_pages_table = re.search('<table class="mw-allpages-table-chunk">(.*)</table>',
html.content, re.DOTALL).group()
titles = re.findall(r'title="([^"]*?)"', all_pages_table)
hrefs = re.findall(r'href="([^"]*?)"', all_pages_table)
print("Go to http://wiki.ipython.org/Special:Export and export the following:")
print('\n'.join(titles))
#!/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 => '[email protected]' }
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