Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Converts tiddlywki tiddlers into files which can be imported into Notational Velocity
- require 'fileutils'
- require 'rexml/document'
- require 'time'
- require 'date'
- tiddlywiki_location = ARGV[0]
- if tiddlywiki_location.nil?
- puts "Please specify the location of your Tiddliwki"
- exit
- end
- # Load in the tiddlywiki
- File.open(tiddlywiki_location, 'r') do |file|
- xml = REXML::Document.new(file.read)
- puts "Parsed wiki file..."
- start = xml.elements['html/body/div[@id=\'storeArea\']']
- if start.nil?
- puts "Looks like this isn't a TiddlyWiki!"
- return
- end
- FileUtils.mkdir("notes") rescue nil
- start.elements.each do |child|
- unless child.attributes['title'].nil?
- # Must have a tiddler
- title = child.attributes['title']
- modifier = child.attributes['modifier']
- created_on = Date.parse(child.attributes['created'])
- updated_on = child.attributes['modified'].nil? ? created_on : Date.parse(child.attributes['modified'])
- tags = child.attributes['tags'].nil? ? [] : child.attributes['tags'].split(' ')
- content = child.elements[1]
- unless content.nil?
- content_data = content.text
- #puts "#{title} #{updated_on}"
- #puts "tags: #{tags}"
- #puts "------"
- #puts content_data
- #puts "######"
- File.open("notes/#{title}.txt", 'w') do |f|
- f.write "#{title}\n\n"
- f.write content_data
- end
- sanitized_title = title.gsub(' ', '\\ ').gsub('(', '\\(').gsub(')', '\\)')
- puts ['touch', '-t', created_on.strftime("%Y%m%d%H%M.%S"), "notes/#{sanitized_title}.txt"].join(' ')
- `touch -t #{created_on.strftime("%Y%m%d%H%M.%S")} notes/#{sanitized_title}.txt`
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment