Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Make the program create valid folder names
Browse files Browse the repository at this point in the history
* Export valid tags instead of their IDs
* Use creation dates as file names

Signed-off-by: Timur Demin <me@tdem.in>
  • Loading branch information
tdemin committed Apr 9, 2019
1 parent 83d7f67 commit 5262d46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion scarlet_export/__init__.py
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion scarlet_export/notable.py
Expand Up @@ -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:
Expand All @@ -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():
Expand Down
15 changes: 12 additions & 3 deletions scarlet_export/note.py
Expand Up @@ -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']

0 comments on commit 5262d46

Please sign in to comment.