Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2015 02:57
Show Gist options
  • Save anonymous/8824ef73e15394e1a565 to your computer and use it in GitHub Desktop.
Save anonymous/8824ef73e15394e1a565 to your computer and use it in GitHub Desktop.
moinmoin 2 dokuwiki
#!/usr/bin/python
from dokuwiki import DokuWiki, DokuWikiError
import sys
import subprocess
import fileinput
import glob
def to_doku(page_id, txt):
try:
d = DokuWiki('http://xx.xx/wiki', 'xx', 'xx', allow_none=True)
except DokuWikiError as err:
print err
# sys.exit(1)
# print d.pages.list()
try:
d.pages.set(page_id, txt)
except DokuWikiError as err:
print err
def cat(f):
return subprocess.check_output('cat '+ f +' | iconv -f cp949 -t utf8' , shell=True)
def moin2doku(f):
return subprocess.check_output('cat '+ f+' | iconv -f cp949 -t utf8 | perl migrate.pl' , shell=True)
import time
for f in glob.glob('*'):
print f
to_doku(f, moin2doku(f))
#!/usr/bin/perl -ni.bak
BEGIN { $readblank = 0; }
$readblank = 1 if /^$/;
# Fix line-endings for Unix
# $//;
# Ignore all pragmas
next if !$readblank and /^#/;
# Fix different a href linking styles
s/\[(http:\S+)\s+(.*?)]/[\[$1|$2\]]/g;
# Fix lists that aren't indented enough
s/^ \*/ \*/;
# Fix ordered lists
s/^(\s+)\d+\./$1-/;
# Fix code blocks
s/^{{{$/<code>/;
s/^}}}$/<\/code>/;
# Fix monospace/code text
s/`/''/g;
s/{{{(.*?)}}}/''$1''/g;
# Fix headers
s/^= (.*) =$/====== $1 ======/g;
s/^== (.*) ==$/===== $1 =====/g;
s/^=== (.*) ===$/==== $1 ====/g;
print;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment