A Chicken Scheme script for exporting wiki pages locally to plain text files. Useful for importing your wiki pages into another application. Probably isn't the best Scheme code, but it works.
; MoinMoin wiki exporter for Chicken Scheme ; Run with 'csi -script moinWikiExporter.scm' (use extras) (use posix) (use regex) (require-extension http-client) ; moinmoin url (define wikiUrl "localhost/mywiki") ; exclude wiki pages regex's (define excludePages (list "Category.*" "Desktop.*" "EventStats.*" "Help.*" "Local.*" "Missing.*" "Moin.*" "Page.*" "Slide.*" "System.*" "Wiki.*")) (define writeLines (lambda (o lines) (display (car lines) o) (newline o) (let ((l (cdr lines))) (unless (null? l) (writeLines o l))))) (define parseWikiLine (lambda (line) ; remove macros (if (string-match "#(.*)" line) (set! line "")) ; remove square brackets and speech marks (set! line (string-substitute* line '(("(\\[|\\[\"|\\]|\"\\])" . "")))) ; convert leading spaces into tabs (set! line (string-substitute* line '(("^ " . "\t")))) ; remove formatting (set! line (string-substitute* line '(("(''|'''|{ { {|} } }|__|\\^|,,|~-|-~|~\\+|\\+~|--)" . "")))) ; remove headings (set! line (string-substitute "(=+) (.*) (=+)" "\\2" line)) ; line)) (define isPageMember? (lambda (page pages) (if (string-match (car pages) page) #t (let ((p (cdr pages))) (if (null? p) #f (isPageMember? page p)))))) (define parseWikiPage (lambda (page) (unless (isPageMember? page excludePages) (let ((url (string-append wikiUrl "/" page "?action=raw"))) (let-values (((h a i o) (http:send-request url))) (pretty-print (string-append "Parsing: " page)) (let ((parsedLines (map parseWikiLine (read-lines i)))) (let ((parsedFile (open-output-file (string-append (string-translate page "/") ".txt")))) (writeLines parsedFile parsedLines) (close-output-port parsedFile))) (close-input-port i) (close-output-port o)))))) (define getWikiPages (let-values (((h a i o) (http:send-request (string-append wikiUrl "/TitleIndex?action=titleindex")))) (let ((pages (read-lines i))) (close-input-port i) (close-input-port o) pages))) (unless (directory? "moin") (create-directory "moin")) (change-directory "moin") (for-each parseWikiPage getWikiPages)