nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 34b1a6c1f5e7e318456e7be7958c3042559db28f
parent 3e4b72ade70f7ae62ea6ebc2a646d15e41e9fcdd
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sun, 29 Jul 2018 19:30:38 -0400

Category modifications working in GUI

Diffstat:
Mnnotes_cli/nextcloud_note.py | 7++++---
Mnnotes_cli/nncli.py | 3+--
Mnnotes_cli/notes_db.py | 37+++++++++++++++++++++++++++++--------
Mtodo.txt | 3++-
4 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/nnotes_cli/nextcloud_note.py b/nnotes_cli/nextcloud_note.py @@ -137,19 +137,20 @@ def update_note(self, note): note["modified"] = int(time.time()) url = '{}/{}'.format(self.api_url, note["id"]) + del note["id"] else: url = self.api_url #logging.debug('REQUEST: ' + url + ' - ' + str(note)) try: logging.debug('NOTE: ' + str(note)) - if "id" in note: + if url != self.api_url: res = requests.put(url, data=note) else: - res = requests.post(url, json=note) + res = requests.post(url, data=note) note = res.json() res.raise_for_status() - logging.debug('NOTE (from response): ' + str(note)) + logging.debug('NOTE (from response): ' + str(res.json())) self.status = 'online' except ConnectionError as e: self.status = 'offline, connection error' diff --git a/nnotes_cli/nncli.py b/nnotes_cli/nncli.py @@ -644,7 +644,6 @@ def gui_frame_keypress(self, size, key): self.master_frame.keypress = self.gui_footer_input_get().keypress elif key == self.config.get_keybind('note_delete'): - logging.debug('Delete key pressed') if self.gui_body_get().__class__ != view_titles.ViewTitles and \ self.gui_body_get().__class__ != view_note.ViewNote: return key @@ -708,7 +707,7 @@ def gui_frame_keypress(self, size, key): user_input.UserInput( self.config, 'Category: ', - '%s' % ','.join(note['category']), + note['category'], self.gui_category_input, None), 'user_input_bar')) diff --git a/nnotes_cli/notes_db.py b/nnotes_cli/notes_db.py @@ -293,7 +293,9 @@ def import_note(self, note): 'content' : note.get('content', ''), 'modified' : modified, 'title' : note.get('title'), - 'category' : note.get('category', None), + 'category' : note.get('category') \ + if note.get('category') is not None \ + else '', 'savedate' : 0, # never been written to disc 'syncdate' : 0, # never been synced with server 'favorite' : False, @@ -308,7 +310,8 @@ def import_note(self, note): if not 0 <= n <= timestamp: raise ValueError('date fields must be real') - if not isinstance(new_note['category'], str): + if not isinstance(new_note['category'], str) or \ + new_note['category'] is None: raise ValueError('"category" must be an string') if not isinstance(new_note['favorite'], bool): @@ -326,17 +329,19 @@ def create_note(self, content): new_key = utils.generate_random_key() timestamp = int(time.time()) + title = content.split('\n')[0] # note has no internal key yet. new_note = { 'localkey' : new_key, 'content' : content, 'modified' : timestamp, - 'category' : None, - 'savedate' : 0, # never been written to disc - 'syncdate' : 0, # never been synced with server + 'category' : '', + 'savedate' : 0, # never been written to disc + 'syncdate' : 0, # never been synced with server 'favorite' : False, - 'deleted' : False + 'deleted' : False, + 'title' : title } self.notes[new_key] = new_note @@ -476,16 +481,24 @@ def sync_notes(self, server_sync=True, full_sync=True): del cn['syncdate'] del cn['savedate'] del cn['deleted'] + if 'etag' in cn: + del cn['etag'] + if 'title' in cn: + del cn['title'] if 'what_changed' in cn: + if 'content' not in cn['what_changed'] \ + and 'category' not in cn['what_changed']: + del cn['content'] if 'category' not in cn['what_changed']: del cn['category'] if 'favorite' not in cn['what_changed']: del cn['favorite'] - if 'content' not in cn['what_changed']: - del cn['content'] del cn['what_changed'] + if 'favorite' in cn: + cn['favorite'] = str.lower(str(cn['favorite'])) + if n['deleted']: uret = self.note.delete_note(cn) else: @@ -497,9 +510,13 @@ def sync_notes(self, server_sync=True, full_sync=True): # record syncdate and save the note at the assigned key del self.notes[local_key] k = uret[0].get('id') + t = uret[0].get('title') + c = uret[0].get('category') + c = c if c is not None else '' n.update(uret[0]) n['syncdate'] = now n['localkey'] = k + n['category'] = c self.notes[k] = n local_updates[k] = True @@ -536,6 +553,8 @@ def sync_notes(self, server_sync=True, full_sync=True): len_nl = len(nl) for note_index, n in enumerate(nl): k = n.get('id') + c = n.get('category') if n.get('category') is not None \ + else '' server_keys[k] = True # this works because in the prior step we rewrite local keys to # server keys when we get an updated note back from the server @@ -549,6 +568,7 @@ def sync_notes(self, server_sync=True, full_sync=True): local_updates[k] = True self.notes[k]['syncdate'] = now self.notes[k]['localkey'] = k + self.notes[k]['category'] = c self.notes[k]['deleted'] = False self.log('Synced newer note from server (key={0})'.format(k)) @@ -563,6 +583,7 @@ def sync_notes(self, server_sync=True, full_sync=True): local_updates[k] = True self.notes[k]['syncdate'] = now self.notes[k]['localkey'] = k + self.notes[k]['category'] = c self.notes[k]['deleted'] = False self.log('Synced new note from server (key={0})'.format(k)) diff --git a/todo.txt b/todo.txt @@ -1,2 +1,3 @@ 1. Pin->Favorite -2. Tags->Category +2. Sort +3. Command line