Pull request #5

Merged
ArneTR merged 3 commits from pull-request into master 2020-06-04 17:37:54 +02:00
Showing only changes of commit cfaadb0602 - Show all commits
-14
View File
@@ -24,7 +24,6 @@ final_file = '''
''' '''
tag_notes_links = {} tag_notes_links = {}
# first we build the tag hash
for key, item in enumerate(data['items']): for key, item in enumerate(data['items']):
if item['content_type'] == 'Tag': if item['content_type'] == 'Tag':
for inner_key, reference in enumerate(item['content']['references']): for inner_key, reference in enumerate(item['content']['references']):
@@ -36,26 +35,17 @@ for key, item in enumerate(data['items']):
else: else:
tag_notes_links[reference['uuid']] = [html.escape(item['content']['title'])] 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']): for key, item in enumerate(data['items']):
if item['content_type'] == 'Note': 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']: 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: else:
title = "empty title" title = "empty title"
text = item['content']['text'] text = item['content']['text']
text = text_from_html(title, text) text = text_from_html(title, 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: 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'.") print(f"Whoops .... {title} had no tag ... if this is expected, then safely ignore ... Setting tag: 'Missing-Standard-Notes-Tag'.")
@@ -71,10 +61,6 @@ for key, item in enumerate(data['items']):
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) 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 final_file += '''</en-export>''' # close root tag