Skip to content

Instantly share code, notes, and snippets.

@AmedeeBulle
Created July 11, 2016 14:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AmedeeBulle/fdc19b9705a5a9e2f9fc41792dee6901 to your computer and use it in GitHub Desktop.
Save AmedeeBulle/fdc19b9705a5a9e2f9fc41792dee6901 to your computer and use it in GitHub Desktop.
Simple script to import (Evernote) notes to Simplenote
#!/usr/bin/env python
"""
e2s: simple script to import (Evernote) notes to Simplenote
This script relies on two projects:
- ever2simple (https://github.com/claytron/ever2simple) to covert Evernote ENEX files to JSON
- simplenote python API (https://pypi.python.org/pypi/simplenote) used in this script to upload the notes
Note: Simplenote expects dates in UNIX Timestamp format. I have posted a pull request for ever2simple
to issue dates in this format, but so far the PR is still pending. In the meantime you shoudl use my fork
(https://github.com/AmedeeBulle/ever2simple)
Process I used to migrate from Evernote to Simplenote:
1. Install ever2simple (my fork) and the simplenote python API (e.g. pip install simplenote)
2. Export your Evernote notes in ENEX format. I exported notebook per notebook to be able to tag
the notes per notebook.
If you export all your notes in one big file, notebooks info will be lost.
3. Using ever2simple convert ENEX files into JSON. E.g. for each file:
ever2simple -o notebook1.json -f json -e notebook1.enex
The '-e' option is important, it writes date in UNIX timestamp format
4. Using this script: upload to Simplenote. E.g.:
e2s.py -t NoteBook1 -u myuser -p mypassword notebook1.json
(-t is optional and allows you to add a tag to all notes)
This script is rather simplistic (no error checking, ...) but worked for me to migrate from Evernote
to Simplenote.
Usual disclaimers: use and enjoy at your own risks...
"""
import argparse
import json
import os
import sys
import simplenote
parser = argparse.ArgumentParser(prog=None, description="Import Evernote json file to Simplenote")
parser.add_argument('json_file', metavar='json-file', help='The path of the Evernote json file')
parser.add_argument('-t', '--tag', help='additional tag to add to notes')
parser.add_argument('-u', '--user', required=True, help='additional tag to add to notes')
parser.add_argument('-p', '--password', required=True, help='additional tag to add to notes')
args, remainder = parser.parse_known_args()
json_file = os.path.expanduser(args.json_file)
try:
with open(json_file) as f:
json_notes = json.load(f)
except IOError as e:
print('Cannot open notes file {0}: Errno {1} - {2}'.format(json_file, e.errno, e.strerror))
sys.exit(1)
except ValueError as e:
print('Cannot parse notes file {0}: {1}'.format(json_file, e.message))
sys.exit(1)
simplenote = simplenote.Simplenote(args.user, args.password)
count = 0
for note in json_notes:
count += 1
# simplenote class expects utf8 strings, but my source is already unicode...
if isinstance(note['content'], unicode):
note['content'] = note['content'].encode('utf-8')
tags = []
for tag in note['tags']:
if isinstance(tag, unicode):
tags.append(tag.encode('utf-8'))
else:
tags.append(tag)
note['tags'] = tags
# Notes from ever2simple are Markdown formatted
note['systemtags'] = ['markdown']
if args.tag:
note['tags'].append(args.tag)
simplenote.add_note(note)
print('{0} notes inserted'.format(count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment