nncli

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

commit 4cd0fb1bd39d80ea5063bd8da965f7caaec3ac7f
parent 461719beb1be3e7934f21e35f82e8ea5f50d3495
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Fri,  1 Apr 2016 17:03:36 +1030

fix comparison functions for sorting notes, convert couple of variables to correct types

Diffstat:
Msimplenote_cli/simplenote.py | 2+-
Msimplenote_cli/sncli.py | 2+-
Msimplenote_cli/utils.py | 19++++++-------------
3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/simplenote_cli/simplenote.py b/simplenote_cli/simplenote.py @@ -59,7 +59,7 @@ def authenticate(self, user, password): """ auth_params = "email=%s&password=%s" % (user, password) - values = base64.encodestring(auth_params) + values = base64.encodestring(auth_params.encode()) request = Request(self.AUTH_URL, values) try: res = urllib.request.urlopen(request).read() diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -240,7 +240,7 @@ def log(self, msg): self.log_alarms += 1 self.logs.append(msg) - if len(self.logs) > self.config.get_config('max_logs'): + if len(self.logs) > int(self.config.get_config('max_logs')): self.log_alarms -= 1 self.logs.pop(0) diff --git a/simplenote_cli/utils.py b/simplenote_cli/utils.py @@ -145,21 +145,14 @@ def sanitise_tags(tags): else: return illegals_removed.split(',') -def sort_by_title_pinned(a, b): - if note_pinned(a.note) and not note_pinned(b.note): - return -1 - elif not note_pinned(a.note) and note_pinned(b.note): - return 1 - else: - return cmp(get_note_title(a.note), get_note_title(b.note)) +def sort_by_title_pinned(a): + return (not note_pinned(a.note), get_note_title(a.note)) -def sort_by_modify_date_pinned(a, b): - if note_pinned(a.note) and not note_pinned(b.note): - return 1 - elif not note_pinned(a.note) and note_pinned(b.note): - return -1 +def sort_by_modify_date_pinned(a): + if note_pinned(a.note): + return 100.0 * float(a.note.get('modifydate', 0)) else: - return cmp(float(a.note.get('modifydate', 0)), float(b.note.get('modifydate', 0))) + return float(a.note.get('modifydate', 0)) class KeyValueObject: """Store key=value pairs in this object and retrieve with o.key.