Work with binary data and catch more exceptions

This commit is contained in:
2017-10-13 18:46:22 -06:00
parent be39849693
commit c7309c4136
4 changed files with 51 additions and 19 deletions
+10 -3
View File
@@ -44,9 +44,16 @@ class ItemManager:
for uuid, item in sorted_items:
if item['content_type'] == 'Note':
note = item['content']
text = note['text'] + '\n'
count = 0 # used to remove title duplicates
text = note['text']
# Add a new line so it outputs pretty
if not text.endswith('\n'):
text += '\n';
text = text.encode() # convert to binary data
# remove title duplicates by adding a number to the end
count = 0
while True:
title = note['title'] + ('' if not count else ' ' + str(count + 1))
if title in notes:
@@ -66,7 +73,7 @@ class ItemManager:
def writeNote(self, uuid, text):
item = self.items[uuid]
item['content']['text'] = text.strip()
item['content']['text'] = text.decode() # convert back to string
item['dirty'] = True
def createNote(self, name, time):