sorting notes in Google Keep - gkeepapi

1.3k Views Asked by At

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('[email protected]', 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.

1

There are 1 best solutions below

3
balderman On

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