From ad0dd8f7e02aceeda50b6edbe9734f2ca0030ad1 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 9 Apr 2019 00:44:52 +0500 Subject: [PATCH] Add most of the export logic Signed-off-by: Timur Demin --- scarlet_export/notable.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/scarlet_export/notable.py b/scarlet_export/notable.py index 10f20b4..88098d3 100644 --- a/scarlet_export/notable.py +++ b/scarlet_export/notable.py @@ -1,3 +1,6 @@ +from datetime import datetime +from json import loads + def exportNotes(inputJson, outputDir): """ Exports the notes from Scarlet Notes to Notable. @@ -5,4 +8,29 @@ def exportNotes(inputJson, outputDir): @param inputJson: an object generated with `json.load()` @param outputDir: output directory name """ - pass + for note in inputJson['notes']: + # color is not available in Notable, so it's not preserved + # the metadata Notable uses is just YAML front matter + if note['folder'] != '': + outputFolder = outputDir + '/' + note['folder'] + else: + outputFolder = outputDir + outputFileName = outputFolder + '/' + note['uuid'] + '.md' + tags = '[{0}]'.format(note['tags']) + timestamp = int(note['timestamp']) + updateTimestamp = int(note['updateTimestamp']) + created = datetime.utcfromtimestamp(timestamp) + modified = datetime.utcfromtimestamp(updateTimestamp) + with open(outputFileName) as output: + # print YAML front matter first, then dump the note content + output.write('---') + output.write('created: {0}'.format(created)) + output.write('modified: {0}'.format(modified)) + output.write('tags: {0}'.format(tags)) + output.write('---') + output.write('') # an empty string + # dump the note text as well, contained in another + # JSON-formatted string + noteText = loads(note['description'])['note']['text'] + output.write(noteText) + return