Python googlekeep-gkeepapi中的笔记排序
我查看了文档中的Python googlekeep-gkeepapi中的笔记排序,python,google-keep,Python,Google Keep,我查看了文档中的gkeepapi,没有任何函数对注释进行排序。但是,注释确实按此处打印的顺序显示: 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
gkeepapi
,没有任何函数对注释进行排序。但是,注释确实按此处打印的顺序显示:
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()
我希望按标题对GNOTE进行排序,然后对其进行更新,这样当我查看Google Keep时,我的笔记会按字母顺序进行排序。因为我不能调用Google notes API,所以我使用笔记替换
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)
输出
BTitle - ,bla
OneTitle - bla
Ztitle - bla
如果我尝试使用Keep.sync(),它实际上不会更新为Google Keep。你是否将此代码称为:@jason我不清楚你想做什么。请您解释并分享代码。您的
gnotes
是一个局部变量。首先从原始(未排序的)注释列表对其进行初始化,然后重新分配该列表的排序版本。没有任何东西可以将该局部变量绑定回Keep服务,因此同步没有任何效果也就不足为奇了。使用gnotes.sort
对列表进行就地排序的可能性非常小,但是find
的三个结果很可能会返回数据的独立副本。阅读API时,我找到了用于排序列表项的代码,但没有找到用于注释的代码。可能要等到谷歌发布一个公共API才能继续。