Skip to content

Instantly share code, notes, and snippets.

@bfroehle
Forked from henare/mw-to-gollum.rb
Last active December 10, 2015 22:08

Revisions

  1. bfroehle revised this gist Jan 10, 2013. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion mw-to-gollum.rb
    Original file line number Diff line number Diff line change
    @@ -11,12 +11,20 @@
    doc.search('/mediawiki/page').each do |el|
    title = el.at('title').inner_text.tr('/', '-')
    content = el.at('text').inner_text
    kind = :mediawiki
    commit = { :message => "Import MediaWiki page #{title} into Gollum",
    :name => 'Bradley M. Froehle',
    :email => '[email protected]' }

    m = content.match(/^\s*<rst>(.*)<\/rst>\s*$/m)
    if m
    kind = :rest
    content = m[1]
    end

    begin
    puts "Writing page #{title}"
    wiki.write_page(title, :mediawiki, content, commit)
    wiki.write_page(title, kind, content, commit)
    rescue Gollum::DuplicatePageError => e
    p "Duplicate #{title}"
    end
  2. bfroehle revised this gist Jan 10, 2013. 1 changed file with 6 additions and 9 deletions.
    15 changes: 6 additions & 9 deletions mw-to-gollum.rb
    Original file line number Diff line number Diff line change
    @@ -2,25 +2,22 @@
    require 'rubygems'
    require 'hpricot'
    require 'gollum'
    require 'open-uri'

    wiki = Gollum::Wiki.new('openaustralia.wiki')
    wiki = Gollum::Wiki.new('ipython.wiki')

    file = File.open("OpenAustralia-20110309232515.xml", "r")

    doc = Hpricot(file)
    doc = Hpricot(open('https://dl.dropbox.com/s/5ogy0xg2lkuo1rf/IPython-20130110012347.xml'))

    doc.search('/mediawiki/page').each do |el|
    title = el.at('title').inner_text
    title = el.at('title').inner_text.tr('/', '-')
    content = el.at('text').inner_text
    commit = { :message => "Import MediaWiki page #{title} into Gollum",
    :name => 'Henare Degan',
    :email => 'henare.degan@gmail.com' }
    :name => 'Bradley M. Froehle',
    :email => 'brad.froehle@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
  3. bfroehle revised this gist Jan 10, 2013. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions ipython_all_pages.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/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))

  4. @henare henare created this gist Mar 10, 2011.
    26 changes: 26 additions & 0 deletions mw-to-gollum.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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