1

I've looked through the docs for gkeepapi, and there isn't any function that sorts the notes. The notes however do appear in Keep as the order printed here:

import gkeepapi
k = gkeeapi.Keep()
k.login('xxxxx@gmail.com', pwd)

gnotes = k.keep.find(pinned=False, trashed=False)
for n in gnotes:
    print(n.title)

gnotes = sorted(gnotes, key=lambda x: x.title)
k.sync()

I am looking to sort the gnotes by title then update it, so that when I look at Google Keep my notes are sorted alphabetically.

jason
  • 3,811
  • 18
  • 92
  • 147
  • Your `gnotes` is a local variable. You first initialize it from the original (unsorted) list of notes, then reassign a sorted version of that list instead. There is nothing to tie that local variable back to the Keep service, so I'm not surprised the sync had no effect. There is a *very* slim chance that sorting the list in place using `gnotes.sort` would get synced, but most likely three result of `find` returns an independent copy of the data. Reading the API I found code for ordering list items but not for notes. Might have to wait till Google publishes a public API for Keep. – MvG Jan 28 '20 at 22:10

1 Answers1

1

Since I cant call Google notes API I use a Note replacement.

class Note:
    def __init__(self, title, other):
        self.title = title
        self.other = other

    def __repr__(self):
        return '{} - {}'.format(self.title, self.other)


gnotes = [Note('OneTitle', 'bla'), Note('Ztitle', 'bla'), Note('BTitle', ',bla')]
gnotes = sorted(gnotes, key=lambda x: x.title)
# gnotes = k.keep.find(pinned=False, trashed=False)
for note in gnotes:
    print(note)

output

BTitle - ,bla
OneTitle - bla
Ztitle - bla
balderman
  • 22,927
  • 7
  • 34
  • 52