parent
171e0529df
commit
8b82f96d4a
3 changed files with 59 additions and 46 deletions
@ -0,0 +1,43 @@ |
|||||||
|
from api import StandardNotesAPI |
||||||
|
|
||||||
|
class ItemManager: |
||||||
|
items = {} |
||||||
|
|
||||||
|
def mapResponseItemsToLocalItems(self, response_items): |
||||||
|
for response_item in response_items: |
||||||
|
uuid = response_item['uuid'] |
||||||
|
|
||||||
|
if response_item['deleted']: |
||||||
|
if uuid in self.items: |
||||||
|
del self.items[uuid] |
||||||
|
continue |
||||||
|
|
||||||
|
self.items[uuid] = response_item |
||||||
|
|
||||||
|
def getNotes(self): |
||||||
|
notes = {} |
||||||
|
sorted_items = sorted(self.items.items(), key=lambda x: x[1]['created_at']) |
||||||
|
|
||||||
|
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 |
||||||
|
|
||||||
|
while True: |
||||||
|
title = note['title'] + ('' if not count else ' ' + str(count + 1)) |
||||||
|
if title in notes: |
||||||
|
count += 1 |
||||||
|
else: |
||||||
|
break |
||||||
|
|
||||||
|
notes[title] = dict(text=text, |
||||||
|
created=item['created_at'], |
||||||
|
modified=item['updated_at'], |
||||||
|
uuid=item['uuid']) |
||||||
|
return notes |
||||||
|
|
||||||
|
def __init__(self, username, password): |
||||||
|
self.standard_notes = StandardNotesAPI(username, password) |
||||||
|
response_items = self.standard_notes.sync(None) |
||||||
|
self.mapResponseItemsToLocalItems(response_items) |
Loading…
Reference in new issue