Created
April 24, 2023 12:37
-
-
Save Noleli/0befd47f85f6bfa8d0025beff533b664 to your computer and use it in GitHub Desktop.
Simplenote to Bear converter
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
from subprocess import run | |
import os | |
import json | |
from datetime import datetime | |
# path to input JSON | |
in_path = os.path.join(os.environ['HOME'], 'Downloads/notes/source/notes.json') | |
# path to output directory. it must exist. | |
out_path = os.path.join(os.environ['HOME'], 'Downloads/for-bear') | |
# read the data | |
with open(in_path) as f: | |
note_data = json.load(f) | |
datetime_format = '%m/%d/%Y %H:%M:%S.%f' | |
def create_note_file(datum): | |
# the note text | |
content = datum['content'] | |
# if there are tags, append them as space-separated hashtags at the end of the text | |
if 'tags' in datum: | |
tags_string = '\n\n' | |
tags_string += ' '.join(['#' + tag for tag in datum['tags']]) | |
content += tags_string | |
# convert times to local timezone (Simplenote is in UTC) and format for SetFile | |
creation_date = datetime.fromisoformat(datum['creationDate']).astimezone() | |
creation_date_str = creation_date.strftime(datetime_format) | |
modification_date = datetime.fromisoformat(datum['lastModified']).astimezone() | |
modification_date_str = modification_date.strftime(datetime_format) | |
# write out the file | |
outfile_path = os.path.join(out_path, datum['id'] + '.md') | |
with open(outfile_path, 'w+') as outfile: | |
outfile.write(content) | |
# set the creation and modification dates | |
run(['SetFile', '-d', creation_date_str, outfile_path]) | |
run(['SetFile', '-m', modification_date_str, outfile_path]) | |
# iterate through the notes | |
for note in note_data['activeNotes']: | |
create_note_file(note) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment