Skip to content

Instantly share code, notes, and snippets.

@adamlogic
Created February 10, 2013 02:19
Show Gist options
  • Save adamlogic/4748036 to your computer and use it in GitHub Desktop.
Save adamlogic/4748036 to your computer and use it in GitHub Desktop.
# This is a simple script to convert an XML file exported
# from Evernote into a bookmarks file that can be imported
# into Pinboard. In my case, all I cared about were notes
# that had a source-url, and all I'm retaining is the title
# and URL. I'm adding a fixed "evernote" tag for all notes.
require 'nokogiri'
def note_attributes(note)
{
href: note.at('source-url').text,
tags: 'evernote',
add_date: note.at('created').text
}
rescue
nil
end
def note_text(note)
note.at('title').text
end
xml_doc = Nokogiri::XML(File.read('evernote.xml'))
html_doc = Nokogiri::HTML::Builder.new do |doc|
doc.html {
doc.body(:onload => 'some_func();') {
doc.dl {
xml_doc.css('note').each do |note|
if note_attributes(note)
doc.dt {
doc.a(note_attributes(note)) {
doc.text note_text(note)
}
}
end
end
}
}
}
end
File.write('evernote.html', html_doc.to_html)
@adamlogic
Copy link
Author

I had to manually manipulate the resulting HTML a bit to get this to work in Pinboard. I think the real key was removing the add_date attribute, as I think it was in the wrong format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment