-
-
Save dobbbri/9ca6edf7cbab103491d4546de1498add to your computer and use it in GitHub Desktop.
Simple script to import (Evernote) notes to Simplenote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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