Skip to content

Instantly share code, notes, and snippets.

@boscono
Last active November 12, 2021 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boscono/5424396 to your computer and use it in GitHub Desktop.
Save boscono/5424396 to your computer and use it in GitHub Desktop.
convert evernote(.enex) into delicious XML
#!/usr/bin/ruby
require 'time'
require 'nokogiri'
file = ARGV[0]
doc = Nokogiri::XML(open(file))
puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
puts "<posts>"
doc.search('note').each do |note|
title = nil
note.search('title').each do |t|
title = t.content
end
url = nil
note.search('source-url').each do |u|
url = u.content
end
tags = []
note.search('tag').each do |t|
tags << t.content
end
created = nil
note.search('created').each do |c|
created = c.content
end
escaped_title = title.encode(:xml => :attr)
escaped_url = url.encode(:xml => :attr)
escaped_tags = tags.join(' ').encode(:xml => :attr)
escaped_created = Time.parse(created).iso8601.encode(:xml => :attr)
puts "<post description=#{escaped_title} href=#{escaped_url} " +
"tag=#{escaped_tags} time=#{escaped_created}/>"
end
puts "</posts>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment