gpt4 book ai didi

javascript - Evernote API NoteStore#updateNote 修改笔记更新时间,无论实际更改哪个字段

转载 作者:太空宇宙 更新时间:2023-11-04 01:59:58 25 4
gpt4 key购买 nike

作者:this ,如果我只修改笔记的标签列表,则不应算作更新。因此 note.updated 保留旧值。

当我使用官方客户端手动添加或删除笔记中的标签时,情况就是如此。

尝试去做

以编程方式向现有笔记(标题为“test01”)添加新标签,同时不更新 note.updated。有点像模拟官方客户端修改标签列表的行为。

使用的Python代码

插入您自己的开发 token 后,它应该可以直接执行。

import uuid
from datetime import datetime

from evernote.api.client import EvernoteClient
from evernote.edam.notestore import NoteStore
from evernote.edam.type.ttypes import Tag, Note


def main():
# create note_store
auth_token = "<MyDevToken>"
note_store = EvernoteClient(token=auth_token, sandbox=True).get_note_store()

# create a new tag
the_tag = create_new_tag(auth_token, note_store, "complex_")
print("Tag (%s, %s) created." % (the_tag.guid, the_tag.name))

# search for the note
note_list = remote_search(auth_token, note_store, "intitle:test01")

# add tag to notes found
for note in note_list.notes:
print("Before: %s, tagGuids=%s" % (note.guid, note.tagGuids))
result_note = tag_note(auth_token, note_store, note, the_tag.guid)
print("After: %s, tagGuids=%s, updated=%s" %\
(result_note.guid, result_note.tagGuids,\
datetime.fromtimestamp(result_note.updated/1000)))
pass

def create_new_tag(auth_token, note_store, tag_name_prefix="complex_") -> Tag:
random_tag_name = tag_name_prefix + str(uuid.uuid4())
my_new_tag = Tag(name=random_tag_name)
return note_store.createTag(auth_token, my_new_tag)

def remote_search(auth_token, note_store, search_string):
my_filter = NoteStore.NoteFilter()
my_filter.words = search_string
my_filter.ascending = False

spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
spec.includeTagGuids = True

return note_store.findNotesMetadata(auth_token, my_filter, 0, 10, spec)

def tag_note(auth_token, note_store, note, tag_guid) -> Note:
if note.tagGuids is None:
note.tagGuids = [tag_guid]
else:
note.tagGuids.append(tag_guid)

return note_store.updateNote(auth_token, note)

if __name__ == '__main__':
main()

结果

  1. [如预期]新标签已成功添加。
  2. [不符合预期] note.updated 已修改。不仅本地数据,远程数据也反射(reflect)了这种修改。我已经用官方网络应用程序检查过了。

额外01

即使我将 tag_note() 更改为:

def tag_note(auth_token, note_store, note, tag_guid) -> Note:
# intentionally doing nothing except updateNote()
return note_store.updateNote(auth_token, note)

结果保持不变。看来无论更改哪个字段,updateNote() api 调用都会修改 note.updated 字段。此行为与官方客户端不一样。

额外02

我什至尝试使用 Javascript API 实现相同的逻辑。结果保持不变。

问题

我做错了什么吗?或者使用 Evernote API 根本不可能做到这一点?

最佳答案

尝试

spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
spec.includeTagGuids = True
spec.includeUpdated = True

这将在 NoteStore.findNotesMetadata 返回的注释中预填充 Note.updated。然后,使用带有 updated 的注释来调用 NoteStore.updateNote,您将看到 updated 字段保留原始值。

关于javascript - Evernote API NoteStore#updateNote 修改笔记更新时间,无论实际更改哪个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46376512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com