Evernote Python API - 如何获取笔记的标签列表?

时间:2017-05-31 01:03:41

标签: python api evernote

这是我列出笔记本及其笔记的代码。我现在正在尝试列出与每个音符关联的标签。有人可以帮忙吗?感谢。

from evernote.api.client import EvernoteClient
from evernote.edam.notestore import NoteStore

dev_token = "dev_token"
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()

user = userStore.getUser()
print
print user.username
print

noteStore = client.get_note_store()
notebooks = noteStore.listNotebooks()

for n in notebooks:
   print "Notebook = " + n.name + " GUID = " + n.guid

   filter = NoteStore.NoteFilter()
   filter.ascending = False
   filter.notebookGuid=n.guid

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

   ourNoteList = noteStore.findNotesMetadata(filter, 0, 25, spec)
   for note in ourNoteList.notes:
      print "%s :: %s" % (note.title, note.guid)
   print

1 个答案:

答案 0 :(得分:0)

如果您使用SELECT * FROM objects WHERE JSON_CONTAINS(components, '1', '$.roles'); 致电NoteStore#findNotesMetadata,则返回的NoteMetadata将包含与这些注释相关联的标记GUID列表。

spec.includeTagGuids = True

或者,如果您只想要标签名称,可以使用NoteStore#getNoteTagNames

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

notesMetadataList = noteStore.findNotesMetadata(filter, 0, 25, spec)
for noteMetadata in notesMetadataList.notes:
   for tagGuid in noteMetadata.tagGuids
       tag = noteStore.getTag(tagGuid)

但最好先调用NoteStore#listTags并创建一个从标记guid到tag的字典,这样你就不必每次都在循环中调用NoteStore#getTag