def retire_project(tag_name, ignore_actions=False, dry_run=False, display_remaining_actions=True): """ Retire the project represented by tag_name """ tag = ewu.tag(name=tag_name) # make sure tag_name starts with "+" if not tag_name.startswith("+"): return tag # if ignore_actions is False, check whether are still associated actions for the project. # if there are actions, then don't retire project. Optionally display actions in Evernote if not ignore_actions: associated_actions = list(ewu.actions_for_project(tag_name)) if len(associated_actions): if display_remaining_actions: from appscript import app evnote = app('Evernote') evnote.open_collection_window(with_query_string = '''notebook:"Action Pending" tag:"{0}"'''.format(tag_name)) return tag_name # before just trying to turn the + to a -, check for existence of the new name. # if the new name exists, we would delete the + tag and apply the - tag to the notes tied to the # + tag # let's take care of the simple case first # do I have logic for finding all notes that have a given tag? # tagging a set of notes with a given tag? retired_tag_name = "-" + tag_name[1:] if ewu.tag(retired_tag_name) is None: tag.name = retired_tag_name else: raise Exception("{0} already exists".format(retired_tag_name)) # change parent reference tag.parentGuid = ewu.tag('.Inactive Projects').guid # move the project note (if it exists) from the project notebook to the retired project notebook project_notes = ewu.notes_metadata(includeTitle=True, includeNotebookGuid=True, tagGuids = [tag.guid], notebookGuid=ewu.notebook(name=':PROJECTS').guid) # with NoteMetadata, how to make change to the corresponding note? # make use of # http://dev.evernote.com/doc/reference/NoteStore.html#Fn_NoteStore_updateNote for note in project_notes: note.notebookGuid = ewu.notebook(name=":PROJECTS--RETIRED").guid ewu.noteStore.updateNote(note) # deal with the associated actions for the project # apply changes to tag ewu.noteStore.updateTag(tag) return tag
userStore = client.get_user_store() user = userStore.getUser() print user.username # <codecell> # get all the notes in the :PROJECTS Notebook import datetime from itertools import islice notes = list(islice(ewu.notes_metadata(includeTitle=True, includeUpdated=True, includeUpdateSequenceNum=True, notebookGuid=ewu.notebook(name=':PROJECTS').guid), None)) # accumulate all the tags that begin with "+" associated with notes in :PROJECTS notebook plus_tags_set = set() for note in notes: tags = ewu.noteStore.getNoteTagNames(note.guid) plus_tags = [tag for tag in tags if tag.startswith("+")] plus_tags_set.update(plus_tags) print note.title, note.guid, note.updateSequenceNum, datetime.datetime.fromtimestamp(note.updated/1000.), \ len(plus_tags) == 1 # TO DO: check that each note has one and only one tag that begins with "+"