Beispiel #1
0
    def handle_save(self, b):

        if self.note is None:
            # create new note
            if not self.title_w.value:
                self.title_w.value = 'Untitled'
            self.content = self.body_w.value
            body = markdown2.markdown(self.content, extras=self.extras)
            try:
                self.note = self.ewu.create_note(self.title_w.value, body, notebookGuid=self.notebook_w.value)
            except Exception as e:
                self.status_w.value = str(e) # should get this right
        else:
            # figure out new changes
            # pass body if it has changed
            if not self.title_w.value:
                self.title_w.value = 'Untitled'
            if self.body_w.value <> self.content:
                try:
                    self.content = self.body_w.value
                    body = markdown2.markdown(self.content, extras=self.extras)
                    self.note = ewu.update_note(self.note, title=self.title_w.value, 
                                                content=body, notebookGuid=self.notebook_w.value)
                except Exception as e:
                    self.status_w.value = str(e) # should get this right
            else:
                try:
                    self.note = ewu.update_note(self.note, title=self.title_w.value, 
                                                notebookGuid=self.notebook_w.value)
                except Exception as e:
                    self.status_w.value = str(e) # should get this right
Beispiel #2
0
    def handle_save(self, b):

        if self.note is None:
            # create new note
            if not self.title_w.value:
                self.title_w.value = 'Untitled'
            self.content = self.body_w.value
            body = markdown2.markdown(self.content, extras=self.extras)
            try:
                # use default notebook for now -- have to figure out how to wire notebook selection in
                self.note = self.ewu.create_note(self.title_w.value, body)
            except Exception as e:
                print(e)
                
        else:
            # figure out new changes
            # pass body if it has changed
            if not self.title_w.value:
                self.title_w.value = 'Untitled'
            if self.body_w.value <> self.content:
                try:
                    self.content = self.body_w.value
                    body = markdown2.markdown(self.content, extras=self.extras)
                    self.note = ewu.update_note(self.note, title=self.title_w.value, 
                                                content=body)
                except Exception as e:
                    print (e)
                    
            else:
                try:
                    self.note = ewu.update_note(self.note, title=self.title_w.value)
                except Exception as e:
                    print (e)
Beispiel #3
0
    def load_notebooks(self):

        self.notebooks = ewu.all_notebooks(refresh=True)
        self.nbcounts = ewu.notebookcounts()

        _options = OrderedDict([(notebook.name, notebook.guid) for notebook in self.notebooks])
        self.notebook_widget.options=_options

        default_nb_guid = [notebook.guid for notebook in self.notebooks if notebook.defaultNotebook is True][0]
        self.notebook_widget.value = default_nb_guid
Beispiel #4
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
client = EvernoteClient(token=dev_token, sandbox=False)

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 "+"
import datetime
import logging
import settings

import EvernoteWebUtil as ewu

from itertools import islice
from evernote.api.client import EvernoteClient

# logging
LOG_FILENAME = 'ewu_test.log'
logging.basicConfig(filename=LOG_FILENAME,
                    level=logging.DEBUG,
                    )

dev_token = settings.authToken
ewu.init(dev_token, sandbox=False)

client = ewu.client
userStore = client.get_user_store()
user = userStore.getUser()


def test_username():
    assert user.username is not None