nncli

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

commit fe9b261e4e3a79b5fa97b19e344f9dfa7713db5d
parent 462e41f95d6c1dd3641d4da39f443fecca42cd56
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Wed,  1 Jun 2016 15:46:39 +0930

use a localkey for all notes to avoid errors where no key assigned

Diffstat:
Msimplenote_cli/notes_db.py | 9+++++++++
Msimplenote_cli/simplenote.py | 2++
Msimplenote_cli/sncli.py | 22++++++++++++----------
Msimplenote_cli/temp.py | 1+
Msimplenote_cli/view_titles.py | 4++--
5 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/simplenote_cli/notes_db.py b/simplenote_cli/notes_db.py @@ -55,6 +55,8 @@ def __init__(self, config, log, update_view): # these notes have just been read, so at this moment # they're in sync with the disc. n['savedate'] = now + # set a localkey to each note in memory + n['localkey'] = localkey # initialise the simplenote instance we're going to use # this does not yet need network access @@ -276,6 +278,7 @@ def create_note(self, content): # note has no internal key yet. new_note = { + 'localkey' : new_key, 'content' : content, 'deleted' : 0, 'modifydate' : timestamp, @@ -371,6 +374,10 @@ def helper_key_to_fname(self, k): def helper_save_note(self, k, note): # Save a single note to disc. fn = self.helper_key_to_fname(k) + # TODO: don't save localkey + # - can't do the following because it updates the note everywhere + # if 'localkey' in note: + # note.pop('localkey') json.dump(note, open(fn, 'w'), indent=2) # record that we saved this to disc. @@ -424,6 +431,8 @@ def sync_notes(self, server_sync=True, full_sync=True): # save note to server, update note with response for note_index, local_key in enumerate(self.notes.keys()): n = self.notes[local_key] + # TODO: don't send localkey with this + if not n.get('key') or \ float(n.get('modifydate')) > float(n.get('syncdate')): diff --git a/simplenote_cli/simplenote.py b/simplenote_cli/simplenote.py @@ -157,6 +157,8 @@ def update_note(self, note): url = '%s/%s' % (self.DATA_URL, note["key"]) else: url = self.DATA_URL + + # TODO: remove localkey temporarily before posting #logging.debug('REQUEST: ' + url + ' - ' + str(note)) try: res = requests.post(url, data=json.dumps(note), params=params) diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -264,7 +264,7 @@ def gui_update_view(self): return try: - cur_key = self.view_titles.note_list[self.view_titles.focus_position].note['key'] + cur_key = self.view_titles.note_list[self.view_titles.focus_position].note['localkey'] except IndexError as e: cur_key = None pass @@ -366,7 +366,7 @@ def gui_tags_input(self, args, tags): else: # self.gui_body_get().__class__ == view_note.ViewNote: note = self.view_note.note - self.ndb.set_note_tags(note['key'], tags) + self.ndb.set_note_tags(note['localkey'], tags) if self.gui_body_get().__class__ == view_titles.ViewTitles: self.view_titles.update_note_title() @@ -511,7 +511,7 @@ def gui_frame_keypress(self, size, key): return None self.view_titles.focus_position += 1 lb.update_note_view( - self.view_titles.note_list[self.view_titles.focus_position].note['key']) + self.view_titles.note_list[self.view_titles.focus_position].note['localkey']) self.gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('view_prev_note'): @@ -524,7 +524,7 @@ def gui_frame_keypress(self, size, key): return None self.view_titles.focus_position -= 1 lb.update_note_view( - self.view_titles.note_list[self.view_titles.focus_position].note['key']) + self.view_titles.note_list[self.view_titles.focus_position].note['localkey']) self.gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('prev_version') or \ @@ -652,7 +652,8 @@ def gui_frame_keypress(self, size, key): if md5_old != md5_new: self.log('Note updated') - self.ndb.set_note_content(note['key'], content) + self.log(note.__repr__()) + self.ndb.set_note_content(note['localkey'], content) if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title() else: # self.gui_body_get().__class__ == view_note.ViewNote: @@ -667,8 +668,9 @@ def gui_frame_keypress(self, size, key): if len(lb.body.positions()) <= 0: return None + self.log(lb.note_list[lb.focus_position].note.__repr__()) self.view_note.update_note_view( - lb.note_list[lb.focus_position].note['key']) + lb.note_list[lb.focus_position].note['localkey']) self.gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('pipe_note'): @@ -714,7 +716,7 @@ def gui_frame_keypress(self, size, key): '{0} (y/n): '.format('Untrash' if note['deleted'] else 'Trash'), '', self.gui_yes_no_input, - [ self.trash_note_callback, note['key'] ]), + [ self.trash_note_callback, note['localkey'] ]), 'user_input_bar')) self.gui_footer_focus_input() self.master_frame.keypress = self.gui_footer_input_get().keypress @@ -736,7 +738,7 @@ def gui_frame_keypress(self, size, key): if 'pinned' in note['systemtags']: pin = 0 else: pin = 1 - self.ndb.set_note_pinned(note['key'], pin) + self.ndb.set_note_pinned(note['localkey'], pin) if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title() @@ -760,7 +762,7 @@ def gui_frame_keypress(self, size, key): if 'markdown' in note['systemtags']: md = 0 else: md = 1 - self.ndb.set_note_markdown(note['key'], md) + self.ndb.set_note_markdown(note['localkey'], md) if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title() @@ -1097,7 +1099,7 @@ def cli_note_edit(self, key): if md5_old != md5_new: self.log('Note updated') - self.ndb.set_note_content(note['key'], content) + self.ndb.set_note_content(note['localkey'], content) self.sync_notes() else: self.log('Note unchanged') diff --git a/simplenote_cli/temp.py b/simplenote_cli/temp.py @@ -8,6 +8,7 @@ def tempfile_create(note, raw=False): if raw: # dump the raw json of the note tf = tempfile.NamedTemporaryFile(suffix='.json', delete=False) + contents = json.dumps(note, indent=2) tf.write(contents.encode('utf-8')) tf.flush() diff --git a/simplenote_cli/view_titles.py b/simplenote_cli/view_titles.py @@ -174,13 +174,13 @@ def update_note_title(self, key=None): self.get_note_title(self.note_list[self.focus_position].note) else: for i in range(len(self.note_list)): - if self.note_list[i].note['key'] == key: + if self.note_list[i].note['localkey'] == key: self.body[i] = self.get_note_title(self.note_list[i].note) def focus_note(self, key): for i in range(len(self.note_list)): if 'key' in self.note_list[i].note and \ - self.note_list[i].note['key'] == key: + self.note_list[i].note['localkey'] == key: self.focus_position = i def keypress(self, size, key):