From 5262d46dce11734c7a4cc39c37e8934abc557343 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 9 Apr 2019 15:40:20 +0500 Subject: [PATCH] Make the program create valid folder names * Export valid tags instead of their IDs * Use creation dates as file names Signed-off-by: Timur Demin --- scarlet_export/__init__.py | 8 +++++++- scarlet_export/notable.py | 3 ++- scarlet_export/note.py | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/scarlet_export/__init__.py b/scarlet_export/__init__.py index a05be8d..3e56e60 100644 --- a/scarlet_export/__init__.py +++ b/scarlet_export/__init__.py @@ -58,8 +58,14 @@ def main(): exit(1) # do parsing notes = [] + tags = {} + for tag in data['tags']: + tags[tag['uuid']] = tag['title'] + folders = {} + for folder in data['folders']: + folders[folder['uuid']] = folder['title'] for note in data['notes']: - parsedNote = Note(note) + parsedNote = Note(note, tags, folders) notes.append(parsedNote) # currently the script only supports a single program to export the # data to diff --git a/scarlet_export/notable.py b/scarlet_export/notable.py index ffa6dc0..67a73f5 100644 --- a/scarlet_export/notable.py +++ b/scarlet_export/notable.py @@ -16,7 +16,6 @@ def exportNotes(notesList, outputDir): outputFolder = outputDir + '/' + note.folder else: outputFolder = outputDir - outputFileName = outputFolder + '/' + note.uuid + '.md' # make up a string containing all of the tags tags = '' for tag in note.tags: @@ -32,6 +31,8 @@ def exportNotes(notesList, outputDir): '%Y-%m-%dT%H:%M:%SZ', modifiedTime ) + outputFileName = outputFolder + '/' \ + + created.replace(':', '') + '.md' # check if the folder exists outputPath = Path(outputFolder) if not outputPath.is_dir(): diff --git a/scarlet_export/note.py b/scarlet_export/note.py index 3dd0b63..695ef07 100644 --- a/scarlet_export/note.py +++ b/scarlet_export/note.py @@ -7,12 +7,21 @@ class Note: The timestamps are both ints in Unix time. UUID and folder are both strings. `content` is a string containing all of the note content. + + `tags` and `folders` are both dictionaries where keys are UUIDs and + values are the actual titles. """ - def __init__(self, note): + def __init__(self, note, tags, folders): self.uuid = note['uuid'] - self.folder = note['folder'] + if note['folder'] != '': + self.folder = folders[note['folder']] + else: + self.folder = '' self.updateTimestamp = int(note['updateTimestamp']) self.timestamp = int(note['timestamp']) - self.tags = note['tags'].split(',') + self.tags = [] + for tag in note['tags'].split(','): + if tag != '': + self.tags.append(tags[tag]) noteContent = loads(note['description']) self.content = noteContent['note'][0]['text']