Skip to content

Instantly share code, notes, and snippets.

@wireframe
Created January 24, 2011 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wireframe/792828 to your computer and use it in GitHub Desktop.
Save wireframe/792828 to your computer and use it in GitHub Desktop.
#convert backpack export into evernote import
require 'rubygems'
require 'hpricot'
require 'builder'
require 'time'
import_file = '/path/to/backpack-export.xml'
export_file = '/path/to/my_evernote_import.enex'
doc = Hpricot.XML(open(import_file))
builder = Builder::XmlMarkup.new
builder.instruct!
builder.declare! :DOCTYPE, :'en-export', :SYSTEM, "http://xml.evernote.com/pub/evernote-export.dtd"
builder.tag! 'en-export', 'export-date' => "20110115T164426Z", :application => "Evernote", :version => "Evernote Mac 2.0.1 (118429)" do |export|
(doc/:note).each do |note|
export.note do |note_element|
text = note.inner_html
content_template = %Q{<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div>#{text.gsub("\n", '<br/>')}</div>
</en-note>}
timestamp = Time.parse note.attributes['created_at']
note_element.content { builder.cdata!(content_template)}
note_element.title note.attributes['title']
note_element.created "#{timestamp.strftime('%Y%m%dT%H%M%S')}Z"
note_element.updated "#{timestamp.strftime('%Y%m%dT%H%M%S')}Z"
note_element.tag! "note-attributes"
end
end
end
File.open export_file, 'w+' do |f|
f << builder.target!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment