Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
dist
/env/
.idea
*.json
*.pyc
*.egg-info/
22 changes: 20 additions & 2 deletions ever2simple/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class EverConverter(object):
"""Evernote conversion runner
"""

fieldnames = ['createdate', 'modifydate', 'content', 'tags']
date_fmt = '%h %d %Y %H:%M:%S'
fieldnames = ['createdate', 'modifydate', 'content', 'tags', 'resources']
date_fmt = '%Y %m %d %H:%M:%S'

def __init__(self, enex_filename, simple_filename=None, fmt='json'):
self.enex_filename = os.path.expanduser(enex_filename)
Expand All @@ -39,10 +39,22 @@ def prepare_notes(self, xml_tree):
notes = []
raw_notes = xml_tree.xpath('//note')
for note in raw_notes:

note_dict = {}
title = note.xpath('title')[0].text
# Use dateutil to figure out these dates
# 20110610T182917Z
resources = []
for resource in note.xpath("resource"):
mime = resource.xpath("mime")[0].text
if mime == "image/png" or "image/jpeg":
try:
r_title = resource.xpath("resource-attributes")[0].xpath("file-name")[0].text
data = resource.xpath("data")[0].text
resources.append({"filename": r_title, "data": data})
except IndexError:
pass
note_dict['resources'] = resources
created_string = parse('19700101T000017Z')
if note.xpath('created'):
created_string = parse(note.xpath('created')[0].text)
Expand Down Expand Up @@ -122,5 +134,11 @@ def _convert_dir(self, notes):
os.makedirs(self.simple_filename)
for i, note in enumerate(notes):
output_file_path = os.path.join(self.simple_filename, str(i) + '.txt')

for resource in note['resources']:
resource_output_path = os.path.join(self.simple_filename, str(i) + "-" + resource['filename'])
rh = open(resource_output_path, "wb")
rh.write(resource["data"].decode("base64"))
rh.close()
with open(output_file_path, 'w') as output_file:
output_file.write(note['content'].encode(encoding='utf-8'))