Last active
March 1, 2021 01:28
-
-
Save qvoid/35f729c3924e0916d4aaec7d5777a8cb to your computer and use it in GitHub Desktop.
This file contains 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/python3 | |
# -*- coding: UTF-8 -*- | |
import json | |
import yaml | |
import datetime | |
import os.path | |
import os | |
with open('./notes.json', 'r') as json_file: | |
json_content = json.load(json_file) | |
def write_yaml_header(note): | |
simple_note_id = note['id'] | |
modified = note['lastModified'] | |
created = note['creationDate'] | |
if 'tags' in note: | |
tags = note['tags'] | |
content = note['content'] | |
title = content.splitlines()[0] | |
if 'markdown' in note: | |
is_markdown = note['markdown'] | |
if is_markdown: | |
title = title.replace("# ", "") | |
print("is_markdown ", is_markdown) | |
print(title) | |
if 'tags' in note: | |
#print(yaml.dump(tags)) | |
print(tags) | |
for tag in tags: | |
print(tag) | |
yaml_obj_format ='{0}: {1}\n' | |
yaml_array_fmt_key = '{0}:\n' | |
yaml_array_fmt_elem = ' - {0}\n' | |
md_file_fmt = '{0}/{1}.md' | |
txt_file_fmt = '{0}/{1}.txt' | |
if is_markdown: | |
file_name = md_file_fmt.format('simple_notes', title) | |
else: | |
file_name = txt_file_fmt.format('simple_notes', title) | |
fileobj = open(file_name, 'w', encoding='utf-8') | |
fileobj.writelines('---\n') | |
#fileobj.writelines(yaml_obj_format.format('simple_note_id', simple_note_id)) | |
fileobj.writelines(yaml_obj_format.format('created', created)) | |
fileobj.writelines(yaml_obj_format.format('modified', modified)) | |
if 'tags' in note: | |
fileobj.writelines(yaml_array_fmt_key.format('tags')) | |
for tag in tags: | |
fileobj.writelines(yaml_array_fmt_elem.format(tag)) | |
fileobj.writelines('---\n\n') | |
fileobj.write(content) | |
fileobj.close() | |
if not os.path.exists("simple_notes"): | |
os.makedirs('simple_notes') | |
# active notes | |
for note in json_content['activeNotes']: | |
write_yaml_header(note) | |
# trashed notes | |
#for note in json_content['trashedNotes']: | |
# print(note) | |
# break | |
#print(json_content['activeNotes']) | |
#print(json_content['trashedNotes']) | |
#print("-------------------------------------\n") | |
#print(json_content['activeNotes'][0]) | |
#print("-------------------------------------\n") | |
#print(json_content['activeNotes'][0]['id']) | |
#print(json_content['activeNotes'][0]['content']) | |
# ISO 8601 format time | |
#print(json_content['activeNotes'][0]['creationDate']) | |
#print(json_content['activeNotes'][0]['lastModified']) | |
#print(json_content['activeNotes'][0]['markdown']) | |
#print(json_content['activeNotes'][0]['tags']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment