Reputation: 1
This is my code for listing notebooks and their notes. I'm now trying to list the tags associated with each note. Can someone help? Thanks.
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
Upvotes: 0
Views: 983
Reputation: 1257
If you call NoteStore#findNotesMetadata with spec.includeTagGuids = True
, the returned NoteMetadata will contain a list of tag GUIDs associated with the notes.
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)
or, if you just want names of tags, you could use NoteStore#getNoteTagNames.
notesMetadataList = noteStore.findNotesMetadata(filter, 0, 25, spec)
for noteMetadata in notesMetadataList.notes:
tagNames = noteStore.getNoteTagNames(noteMetadata.guid)
But it would be better to call NoteStore#listTags at first and create a dictionary from tag guids to tag so that you don't have to call NoteStore#getTag every time in the loop.
Upvotes: 1