Skip to content

Instantly share code, notes, and snippets.

@f440
Created April 20, 2014 14:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save f440/11115568 to your computer and use it in GitHub Desktop.
Save f440/11115568 to your computer and use it in GitHub Desktop.
Evernote xml (enex) to txt
#!/usr/bin/env ruby
#-*- encoding: utf-8 -*-
# http://blog.evernote.com/tech/2013/08/08/evernote-export-format-enex/
require 'nokogiri'
require 'date'
require 'ostruct'
class Note < OpenStruct; end
class Notes < Array; end
notes = Notes.new
xml = Nokogiri::XML(File.open(ARGV[0]))
xml.xpath("//note").each do |n|
note = Note.new
note.title = n.xpath('title').first.content
note.content_xml = n.xpath('content').first.content
note.content = Nokogiri::XML(note.content_xml).content
note.created = DateTime.parse(n.xpath('created').first.content)
note.updated = DateTime.parse(n.xpath('updated').first.content)
note.tags = n.xpath('tag').map(&:content)
note.attributes = n.xpath('note-attributes')
.children
.inject({}){|h, i| h[i.name] = i.content ; h }
notes << note
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment