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
13 changes: 10 additions & 3 deletions ever2simple/converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import os
import sys
import datetime
import pytz
from csv import DictWriter
from cStringIO import StringIO
from dateutil.parser import parse
Expand All @@ -15,7 +17,7 @@ class EverConverter(object):
fieldnames = ['createdate', 'modifydate', 'content', 'tags']
date_fmt = '%h %d %Y %H:%M:%S'

def __init__(self, enex_filename, simple_filename=None, fmt='json'):
def __init__(self, enex_filename, simple_filename=None, fmt='json', epoch=False):
self.enex_filename = os.path.expanduser(enex_filename)
self.stdout = False
if simple_filename is None:
Expand All @@ -24,6 +26,7 @@ def __init__(self, enex_filename, simple_filename=None, fmt='json'):
else:
self.simple_filename = os.path.expanduser(simple_filename)
self.fmt = fmt
self.epoch = epoch

def _load_xml(self, enex_file):
try:
Expand All @@ -49,8 +52,12 @@ def prepare_notes(self, xml_tree):
updated_string = created_string
if note.xpath('updated'):
updated_string = parse(note.xpath('updated')[0].text)
note_dict['createdate'] = created_string.strftime(self.date_fmt)
note_dict['modifydate'] = updated_string.strftime(self.date_fmt)
if self.epoch:
note_dict['createdate'] = int((created_string - datetime.datetime(1970,1,1,tzinfo=pytz.utc)).total_seconds())
note_dict['modifydate'] = int((updated_string - datetime.datetime(1970,1,1,tzinfo=pytz.utc)).total_seconds())
else:
note_dict['createdate'] = created_string.strftime(self.date_fmt)
note_dict['modifydate'] = updated_string.strftime(self.date_fmt)
tags = [tag.text for tag in note.xpath('tag')]
if self.fmt == 'csv':
tags = " ".join(tags)
Expand Down
3 changes: 2 additions & 1 deletion ever2simple/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def main():
parser.add_argument('enex-file', help="the path to the Evernote.enex file")
parser.add_argument('-o', '--output', help="the path to the output file or directory, leave black to output to the terminal (stdout)")
parser.add_argument('-f', '--format', help="the output format, json, csv or a directory", choices=['json', 'csv', 'dir'], default='json')
parser.add_argument('-e', '--epoch', help="Write dates UNIX timestamp format", action="store_true")
args = parser.parse_args()
enex_file = vars(args)['enex-file']
output = args.output
Expand All @@ -17,7 +18,7 @@ def main():
if not os.path.exists(filepath):
print 'File does not exist: %s' % filepath
sys.exit(1)
converter = EverConverter(filepath, simple_filename=output, fmt=fmt)
converter = EverConverter(filepath, simple_filename=output, fmt=fmt, epoch=args.epoch)
converter.convert()
sys.exit()

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'lxml',
'python-dateutil<2.0',
'html2text',
'pytz'
],
entry_points="""
[console_scripts]
Expand Down