Pull request #5
@@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import html
|
import html
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
source = argv[1] if len(argv) > 1 else 'notes.txt'
|
source = argv[1] if len(argv) > 1 else 'notes.txt'
|
||||||
@@ -21,14 +23,62 @@ final_file = '''
|
|||||||
<en-export export-date="20171228T194211Z" application="Evernote" version="Evernote Mac 6.13.3 (455969)">
|
<en-export export-date="20171228T194211Z" application="Evernote" version="Evernote Mac 6.13.3 (455969)">
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
tag_notes_links = {}
|
||||||
|
# first we build the tag hash
|
||||||
for key, item in enumerate(data['items']):
|
for key, item in enumerate(data['items']):
|
||||||
if 'title' in item['content'] and 'text' in item['content']:
|
if item['content_type'] == 'Tag':
|
||||||
|
for inner_key, reference in enumerate(item['content']['references']):
|
||||||
|
if 'uuid' not in reference:
|
||||||
|
print(f"Missing UUID for one entry in {reference} ... this can happen sometimes ... reason so far unclear")
|
||||||
|
continue
|
||||||
|
if reference['uuid'] in tag_notes_links:
|
||||||
|
tag_notes_links[reference['uuid']].append(html.escape(item['content']['title']))
|
||||||
|
else:
|
||||||
|
tag_notes_links[reference['uuid']] = [html.escape(item['content']['title'])]
|
||||||
|
|
||||||
|
|
||||||
|
#print (json.dumps(tag_notes_links, indent=2))
|
||||||
|
#quit()
|
||||||
|
|
||||||
|
counter = 0
|
||||||
|
for key, item in enumerate(data['items']):
|
||||||
|
if item['content_type'] == 'Note':
|
||||||
|
|
||||||
|
# if 'title' in item['content'] and 'text' in item['content']: # tís this if really needed?
|
||||||
|
|
||||||
|
if 'title' in item['content']:
|
||||||
title = item['content']['title']
|
title = item['content']['title']
|
||||||
title = html.escape(title)
|
title = html.escape(title)
|
||||||
|
# title = re.sub(r'\\([^\w])', r'\1', title) # if you have mal-imported notes from earliner in SN, then this de-escaping may help you
|
||||||
|
else:
|
||||||
|
title = "empty title"
|
||||||
|
|
||||||
text = item['content']['text']
|
text = item['content']['text']
|
||||||
text = text_from_html(title, text)
|
text = text_from_html(title, text)
|
||||||
final_file += '''<note><title>{title}</title><content><![CDATA[<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>{text}</en-note>]]></content><created>20171228T194130Z</created><updated>20171228T194141Z</updated><note-attributes><author></author><source></source><reminder-order>0</reminder-order></note-attributes></note>'''.format(title=title, text=text)
|
#text = re.sub(r'\\([^\w])', r'\1', text) # if you have mal-imported notes from earliner in SN, then this de-escaping may help you
|
||||||
|
|
||||||
|
if item['uuid'] not in tag_notes_links:
|
||||||
|
print(f"Whoops .... {title} had no tag ... if this is expected, then safely ignore ... Setting tag: 'Missing-Standard-Notes-Tag'.")
|
||||||
|
tag = 'Missing-Standard-Notes-Tag'
|
||||||
|
else:
|
||||||
|
tag = '</tag><tag>'.join(tag_notes_links[item['uuid']])
|
||||||
|
|
||||||
|
# remove miliseconds and timezone ... example: 2020-04-14T14:30:09.256Z => 2020-04-14T14:30:09
|
||||||
|
# we assume zulu time for all dates (UTC)
|
||||||
|
created_at = datetime.datetime.strptime(item['created_at'][0:19], '%Y-%m-%dT%H:%M:%S').strftime('%Y%m%dT%H%M%SZ')
|
||||||
|
updated_at = datetime.datetime.strptime(item['updated_at'][0:19], '%Y-%m-%dT%H:%M:%S').strftime('%Y%m%dT%H%M%SZ')
|
||||||
|
|
||||||
|
|
||||||
|
final_file += '''<note><title>{title}</title><content><![CDATA[<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>{text}</en-note>]]></content><created>{created_at}</created><updated>{updated_at}</updated><tag>{tag}</tag><note-attributes><author></author><source></source><reminder-order>0</reminder-order></note-attributes></note>'''.format(title=title, text=text, tag=tag, created_at=created_at, updated_at=updated_at)
|
||||||
|
|
||||||
|
counter += 1 # uncommet following lines if you want to limit import
|
||||||
|
#if counter > 500: # only process 500 notes
|
||||||
|
# break
|
||||||
|
|
||||||
|
final_file += '''</en-export>''' # close root tag
|
||||||
|
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
with open("notes.enex", "w") as text_file:
|
with open("notes.enex", "w") as text_file:
|
||||||
text_file.write(final_file)
|
text_file.write(final_file)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user