Skip to content

Instantly share code, notes, and snippets.

Created April 24, 2023 12:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simplenote to Bear converter
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:
# 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']:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment