예제 #1
0
    def notes_to_df(self, notes):

        def j_(items):
            return ",".join(items)

        notes_data = []

        for note in notes:
            tags = [ewu.tag(guid=tagGuid).name for tagGuid in note.tagGuids] if note.tagGuids is not None else []
            plus_tags = [tag for tag in tags if tag.startswith("+")]
            context_tags = [tag for tag in tags if tag.startswith("@")]
            when_tags = [tag for tag in tags if tag.startswith("#")]
            other_tags = [tag for tag in tags if tag[0] not in ['+', '@', '#']]


            notes_data.append(dict([('title',note.title), 
                                    ('guid',note.guid), 
                                    ('created', datetime.datetime.fromtimestamp(note.created/1000.)),
                                    ('updated', datetime.datetime.fromtimestamp(note.updated/1000.)),
                                    ('plus', j_(plus_tags)),
                                    ('context', j_(context_tags)),  
                                    ('when', j_(when_tags)), 
                                    ('other', j_(other_tags))
                                    ])
            )

        notes_df = DataFrame(notes_data,
                      columns=['title','guid','created','updated','plus', 'context', 'when', 'other'])  

        return notes_df
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
# <markdowncell>

# # utility for deactivating an active project
# 
# Steps:
# 
# * rename tag "+TagName" to "-TagName"  (checking for possible name collision)
# * move the new tag to be a child of the .Inactive Projects tag
# * move the note to Projects Retired

# <codecell>

# all children of ".Active Projects" tag

[tag for tag in ewu.all_tags() if tag.parentGuid == ewu.tag(name=".Active Projects").guid]

# <codecell>

# make sure that + tags have the right parent (.Active Projects)
# THIS IS USEFUL

active_projects_tag = ewu.tag(name=".Active Projects")
inactive_projects_tag = ewu.tag(name=".Inactive Projects")

wayward_plus_tags = [tag for tag in ewu.all_tags(refresh=True) if tag.name.startswith("+") and tag.parentGuid != active_projects_tag.guid]
for tag in wayward_plus_tags:
    print tag.name
    tag.parentGuid = active_projects_tag.guid
    ewu.noteStore.updateTag(tag)