Evernote API NoteStore#updateNote 修改笔记更新时间 不管哪个字段实际被改变

Evernote API NoteStore#updateNote modifies note updated time no matter which field is actually changed

来自 this, 如果我只修改笔记的标签列表,则不应将其视为更新。因此 note.updated 仍然是旧值。

当我用官方客户端手动添加或删除笔记中的标签时,这是真的。

正在努力

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

Python 使用的代码

插入自己的dev 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 已修改。不仅是本地数据,远程数据也反映了这种修改。我已经用官方网络应用程序检查过了。

额外 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字段保留了原始值。