Bring code up to PEP8 standard
This commit is contained in:
+22
-24
@@ -1,10 +1,11 @@
|
||||
from api import StandardNotesAPI
|
||||
from uuid import uuid1
|
||||
|
||||
from api import StandardNotesAPI
|
||||
|
||||
class ItemManager:
|
||||
items = {}
|
||||
|
||||
def mapResponseItemsToLocalItems(self, response_items, metadata_only=False):
|
||||
def map_items(self, response_items, metadata_only=False):
|
||||
DATA_KEYS = ['content', 'enc_item_key', 'auth_hash']
|
||||
|
||||
for response_item in response_items:
|
||||
@@ -25,7 +26,7 @@ class ItemManager:
|
||||
continue
|
||||
self.items[uuid][key] = value
|
||||
|
||||
def syncItems(self):
|
||||
def sync_items(self):
|
||||
dirty_items = [item for uuid, item in self.items.items() if item['dirty']]
|
||||
|
||||
# remove keys (note: this removes them from self.items as well)
|
||||
@@ -34,12 +35,13 @@ class ItemManager:
|
||||
item.pop('updated_at', None)
|
||||
|
||||
response = self.sn_api.sync(dirty_items)
|
||||
self.mapResponseItemsToLocalItems(response['response_items'])
|
||||
self.mapResponseItemsToLocalItems(response['saved_items'], metadata_only=True)
|
||||
self.map_items(response['response_items'])
|
||||
self.map_items(response['saved_items'], metadata_only=True)
|
||||
|
||||
def getNotes(self):
|
||||
def get_notes(self):
|
||||
notes = {}
|
||||
sorted_items = sorted(self.items.items(), key=lambda x: x[1]['created_at'])
|
||||
sorted_items = sorted(
|
||||
self.items.items(), key=lambda x: x[1]['created_at'])
|
||||
|
||||
for uuid, item in sorted_items:
|
||||
if item['content_type'] == 'Note':
|
||||
@@ -55,49 +57,45 @@ class ItemManager:
|
||||
# remove title duplicates by adding a number to the end
|
||||
count = 0
|
||||
while True:
|
||||
title = note['title'] + ('' if not count else ' ' + str(count + 1))
|
||||
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'],
|
||||
notes[title] = dict(
|
||||
text=text, created=item['created_at'],
|
||||
modified=item.get('updated_at', item['created_at']),
|
||||
uuid=item['uuid'])
|
||||
return notes
|
||||
|
||||
def touchNote(self, uuid):
|
||||
def touch_note(self, uuid):
|
||||
item = self.items[uuid]
|
||||
item['dirty'] = True
|
||||
|
||||
def writeNote(self, uuid, text):
|
||||
def write_note(self, uuid, text):
|
||||
item = self.items[uuid]
|
||||
item['content']['text'] = text.decode() # convert back to string
|
||||
item['dirty'] = True
|
||||
|
||||
def createNote(self, name, time):
|
||||
def create_note(self, name, time):
|
||||
uuid = str(uuid1())
|
||||
content = dict(title=name, text='', references=[])
|
||||
self.items[uuid] = dict(content_type='Note',
|
||||
dirty=True,
|
||||
auth_hash=None,
|
||||
uuid=uuid,
|
||||
created_at=time,
|
||||
updated_at=time,
|
||||
enc_item_key='',
|
||||
content=content)
|
||||
self.items[uuid] = dict(content_type='Note', dirty=True, auth_hash=None,
|
||||
uuid=uuid, created_at=time, updated_at=time,
|
||||
enc_item_key='', content=content)
|
||||
|
||||
def renameNote(self, uuid, new_note_name):
|
||||
def rename_note(self, uuid, new_note_name):
|
||||
item = self.items[uuid]
|
||||
item['content']['title'] = new_note_name
|
||||
item['dirty'] = True
|
||||
|
||||
def deleteNote(self, uuid):
|
||||
def delete_note(self, uuid):
|
||||
item = self.items[uuid]
|
||||
item['deleted'] = True
|
||||
item['dirty'] = True
|
||||
|
||||
def __init__(self, sn_api):
|
||||
self.sn_api = sn_api
|
||||
self.syncItems()
|
||||
self.sync_items()
|
||||
|
||||
Reference in New Issue
Block a user