Skip to content

Instantly share code, notes, and snippets.

@xiaoganghan
Created July 27, 2012 07:26

Revisions

  1. @tinycd tinycd revised this gist Jul 27, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parse_evernote.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    from lxml import etree
    from StringIO import StringIO

    #http://www.hanxiaogang.com/writing/parsing-evernote-export-file-enex-using-python/
    p = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
    def parseNoteXML(xmlFile):
    context = etree.iterparse(xmlFile, encoding='utf-8', strip_cdata=False)
  2. @tinycd tinycd revised this gist Jul 27, 2012. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    [{'content': ['\nyank for copy, delete for cut, put for parse\n',
    None,
    None,
    'Move in context, not position',
    '/ search forward',
    '? search backward',
    'n repeat last search',
    'N repeat last search but in the opposite direction',
    "tx move to 'x'",
    "fx find 'x'"],
    'created': '20101229T161500Z',
    'note': None,
    'note-attributes': None,
    'title': 'Vim Tips',
    'updated': '20101231T161039Z'}]
  3. @tinycd tinycd renamed this gist Jul 27, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @tinycd tinycd renamed this gist Jul 27, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @tinycd tinycd renamed this gist Jul 27, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @tinycd tinycd revised this gist Jul 27, 2012. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions gistfile1.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export2.dtd">
    <en-export export-date="20120727T073610Z" application="Evernote" version="Evernote Mac 3.0.5 (209942)">
    <note><title>Vim Tips</title><content><![CDATA[<?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;">
    yank for copy, delete for cut, put for parse
    <div><br/></div>
    <div>Move in context, not position</div>
    <div>/ search forward</div>
    <div>? search backward</div>
    <div>n repeat last search</div>
    <div>N repeat last search but in the opposite direction</div>
    <div>tx move to 'x'</div>
    <div>fx find 'x'</div>
    </en-note>
    ]]></content><created>20101229T161500Z</created><updated>20101231T161039Z</updated><note-attributes/></note>
    </en-export>
  7. @tinycd tinycd revised this gist Jul 27, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions parse_evernote
    Original file line number Diff line number Diff line change
    @@ -21,3 +21,6 @@ def parseNoteXML(xmlFile):
    notes.append(note_dict)
    note_dict = {}
    return notes

    if __name__ == '__main__':
    notes = parseNoteXML('mynote.enex')
  8. @tinycd tinycd created this gist Jul 27, 2012.
    23 changes: 23 additions & 0 deletions parse_evernote
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    from lxml import etree
    from StringIO import StringIO

    p = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
    def parseNoteXML(xmlFile):
    context = etree.iterparse(xmlFile, encoding='utf-8', strip_cdata=False)
    note_dict = {}
    notes = []
    for ind, (action, elem) in enumerate(context):
    text = elem.text
    if elem.tag == 'content':
    text = []
    r = etree.parse(StringIO(elem.text.encode('utf-8')), p)
    for e in r.iter():
    try:
    text.append(e.text)
    except:
    print 'cannot print'
    note_dict[elem.tag] = text
    if elem.tag == "note":
    notes.append(note_dict)
    note_dict = {}
    return notes