-
Notifications
You must be signed in to change notification settings - Fork 0
/
evernotehtml_to_dayone.py
69 lines (56 loc) · 2.02 KB
/
evernotehtml_to_dayone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""
Move notes from Evernote to DayOne2 on Mac
ILHO AHN ([email protected])
----
PROCEDURE
1 ) Open Evernote and select notes for export.
2 ) Right click and click 'Export Note...' to call 'Export Selected Notes' window.
3 ) Change Format to 'HTML' and save anywhere
4 ) To install DayOne2 CLI run 'sudo /Applications/Day\ One.app/Contents/Resources/install_cli.sh' on Terminal
5 ) Run 'python evernotehtml_to_dayone.py' on Terminal app
If you get some error for not found library 'BeautifulSoup', run 'pip install beautifulsoup4'
"""
import os
import urllib
import sys
from bs4 import BeautifulSoup
from subprocess import call
# Decode image path
def decode_img_path(img_path):
return '%s/%s' % (evernote_html_path, urllib.unquote((str(img_path))))
# parse html to dict
def read_html(html_path):
with open(html_path, 'r') as html_file:
html = html_file.read()
soup = BeautifulSoup.BeautifulSoup(html)
texts = soup.find('body').findAll(text=True)
doc = {'date': soup.find('meta', {'name': 'created'})['content'],
'img': map(lambda x: decode_img_path(x['src']), soup.findAll('img')),
'text': '\n'.join(texts)
}
return doc
# insert to dayone using dayone2 cli
def insert_dayone(doc):
command = ['dayone2', 'new', doc['text'], '-d', doc['date']]
# journal = doc['date'].split('-')[0]
# command.extend(['-j', journal])
if len(doc['img']):
command.append('-p')
for img in doc['img']:
command.append(img)
print command
print call(command)
# Exported evernote html path
evernote_html_path = sys.argv[1]
print 'target path : %s' % evernote_html_path
for html_path in os.listdir(evernote_html_path):
# Onely .html file and except index.html file
if html_path.find('.html') < 0 or html_path == 'index.html':
continue
# Parsing
parsed_doc = read_html('%s/%s' % (evernote_html_path, html_path))
print parsed_doc
# Insert
insert_dayone(parsed_doc)
print 'END JOB'