nncli

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

commit 7b84e1a67f246eb338cd597b8bd0c91a48fdeb56
parent 4110c45c2baf91345a2614e5bfa528138a862818
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Fri,  1 Apr 2016 18:16:50 +1030

commented out note str encoding/decoding (no longer needed), small fixes to smooth things out. seems stable now

Diffstat:
Msimplenote_cli/notes_db.py | 2+-
Msimplenote_cli/simplenote.py | 44++++++++++++++++++++++----------------------
Msimplenote_cli/sncli.py | 4+++-
Msimplenote_cli/temp.py | 2+-
4 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/simplenote_cli/notes_db.py b/simplenote_cli/notes_db.py @@ -371,7 +371,7 @@ 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) - json.dump(note, open(fn, 'wb'), indent=2) + json.dump(note, open(fn, 'w'), indent=2) # record that we saved this to disc. note['savedate'] = time.time() diff --git a/simplenote_cli/simplenote.py b/simplenote_cli/simplenote.py @@ -121,11 +121,11 @@ def get_note(self, noteid, version=None): return e, -1 note = res.json() - # use UTF-8 encoding - note["content"] = note["content"].encode('utf-8') - # For early versions of notes, tags not always available - if "tags" in note: - note["tags"] = [t.encode('utf-8') for t in note["tags"]] + # # use UTF-8 encoding + # note["content"] = note["content"].encode('utf-8') + # # For early versions of notes, tags not always available + # if "tags" in note: + # note["tags"] = [t.encode('utf-8') for t in note["tags"]] #logging.debug('RESPONSE OK: ' + str(note)) return note, 0 @@ -143,18 +143,18 @@ def update_note(self, note): - status (int): 0 on sucesss and -1 otherwise """ - # use UTF-8 encoding - # cpbotha: in both cases check if it's not unicode already - # otherwise you get "TypeError: decoding Unicode is not supported" - if "content" in note: - if isinstance(note["content"], str): - note["content"] = str(note["content"], 'utf-8') - - if "tags" in note: - # if a tag is a string, unicode it, otherwise pass it through - # unchanged (it's unicode already) - # using the ternary operator, because I like it: a if test else b - note["tags"] = [str(t, 'utf-8') if isinstance(t, str) else t for t in note["tags"]] + # # use UTF-8 encoding + # # cpbotha: in both cases check if it's not unicode already + # # otherwise you get "TypeError: decoding Unicode is not supported" + # if "content" in note: + # if isinstance(note["content"], str): + # note["content"] = str(note["content"], 'utf-8') + # + # if "tags" in note: + # # if a tag is a string, unicode it, otherwise pass it through + # # unchanged (it's unicode already) + # # using the ternary operator, because I like it: a if test else b + # note["tags"] = [str(t, 'utf-8') if isinstance(t, str) else t for t in note["tags"]] # determine whether to create a new note or updated an existing one params = {'auth': self.get_token(), @@ -174,11 +174,11 @@ def update_note(self, note): #logging.debug('RESPONSE ERROR: ' + str(e)) return e, -1 note = res.json() - if "content" in note: - # use UTF-8 encoding - note["content"] = note["content"].encode('utf-8') - if "tags" in note: - note["tags"] = [t.encode('utf-8') for t in note["tags"]] + # if "content" in note: + # # use UTF-8 encoding + # note["content"] = note["content"].encode('utf-8') + # if "tags" in note: + # note["tags"] = [t.encode('utf-8') for t in note["tags"]] #logging.debug('RESPONSE OK: ' + str(note)) return note, 0 diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -215,7 +215,9 @@ def log_timeout(self, loop, arg): self.gui_footer_log_clear() self.logs = [] else: - self.logs.pop(0) + # for some reason having problems with this being empty? + if len(self.logs) > 0: + self.logs.pop(0) log_pile = [] diff --git a/simplenote_cli/temp.py b/simplenote_cli/temp.py @@ -40,5 +40,5 @@ def tempfile_content(tf): # This seems like a hack. When editing with Gedit, tf file contents weren't getting # updated in memory, even though it successfully saved on disk. updated_tf_contents = open(tf.name, 'r').read() - tf.write(updated_tf_contents) + tf.write(updated_tf_contents.encode("utf-8")) return updated_tf_contents