【问题标题】:sorting notes in Google Keep - gkeepapi在 Google Keep 中排序笔记 - gkeepapi
【发布时间】:2019-06-23 18:36:30
【问题描述】:

我查看了gkeepapi 的文档,但没有任何功能可以对笔记进行排序。然而,这些注释确实会按照此处打印的顺序出现在 Keep 中:

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()

我希望按标题对 gnotes 进行排序,然后对其进行更新,以便当我查看 Google Keep 时,我的笔记按字母顺序排序。

【问题讨论】:

  • 您的gnotes 是一个局部变量。您首先从原始(未排序的)笔记列表中对其进行初始化,然后重新分配该列表的排序版本。没有什么可以将该局部变量与 Keep 服务联系起来,因此同步没有效果我并不感到惊讶。使用gnotes.sort 对列表进行就地排序的可能性非常会得到同步,但find 的三个结果很可能会返回数据的独立副本。阅读 API 我发现了用于排序列表项的代码,但不是用于注释的代码。可能需要等到 Google 发布 Keep 的公共 API。

标签: python google-keep


【解决方案1】:

由于我无法调用 Google notes API,我使用了 Note 替换。

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-17
  • 1970-01-01
  • 2019-04-26
  • 2019-07-28
相关资源
最近更新 更多