Exemple #1
0
    def updateNote(self,
                   guid,
                   title=None,
                   content=None,
                   tags=None,
                   notebook=None,
                   resources=None):
        note = Types.Note()
        note.guid = guid
        if title:
            note.title = title

        if content:
            note.content = content

        if tags:
            note.tagNames = tags

        if notebook:
            note.notebookGuid = notebook

        if resources:
            """ TODO """
            print("Updating a note's resources is not yet supported.")
            raise NotImplementedError()

        logging.debug("Update note : %s", note)

        self.getNoteStore().updateNote(self.authToken, note)
        return True
Exemple #2
0
    def updateNote(self, guid, title=None, content=None,
                   tags=None, notebook=None, resources=None):
        note = Types.Note()
        note.guid = guid
        if title:
            note.title = title

        if content:
            note.content = content

        if tags:
            note.tagNames = tags

        if notebook:
            note.notebookGuid = notebook

        if resources:
            """ TODO """
            print("Updating a note's resources is not yet supported.")
            raise NotImplementedError()

        logging.debug("Update note : %s", note)

        self.getNoteStore().updateNote(self.authToken, note)
        return True
Exemple #3
0
    def createNotebook(self, name):
        notebook = Types.Notebook()
        notebook.name = name

        logging.debug("New notebook : %s", notebook)

        result = self.getNoteStore().createNotebook(self.authToken, notebook)
        return result
Exemple #4
0
    def createTag(self, name):
        tag = Types.Tag()
        tag.name = name

        logging.debug("New tag : %s", tag)

        result = self.getNoteStore().createTag(self.authToken, tag)
        return result
Exemple #5
0
    def createNotebook(self, name):
        notebook = Types.Notebook()
        notebook.name = name

        logging.debug("New notebook : %s", notebook)

        result = self.getNoteStore().createNotebook(self.authToken, notebook)
        return result
Exemple #6
0
    def createTag(self, name):
        tag = Types.Tag()
        tag.name = name

        logging.debug("New tag : %s", tag)

        result = self.getNoteStore().createTag(self.authToken, tag)
        return result
Exemple #7
0
    def createNote(self, title, content, tags=None, notebook=None, created=None, resources=None):
        
        def make_resource(filename):
            try:
                mtype = mimetypes.guess_type(filename)[0]
                    
                if mtype.split('/')[0] == "text":
                    rmode = "r"
                else:
                    rmode = "rb"

                with open(filename, rmode) as f:
                    """ file exists """
                    resource = Types.Resource()
                    resource.data = Types.Data()

                    data = f.read()
                    md5 = hashlib.md5()
                    md5.update(data)
                    
                    resource.data.bodyHash = md5.hexdigest() 
                    resource.data.body = data
                    resource.data.size = len(data) 
                    resource.mime = mtype
                    resource.attributes = Types.ResourceAttributes()
                    resource.attributes.fileName = os.path.basename(filename)
                    return resource
            except IOError:
                msg = "The file '%s' does not exist." % filename
                out.failureMessage(msg)
                raise IOError(msg)

        note = Types.Note()
        note.title = title
        note.content = content
        note.created = created

        if tags:
            note.tagNames = tags

        if notebook:
            note.notebookGuid = notebook

        if resources:
            """ make EverNote API resources """
            note.resources = map(make_resource, resources)
            
            """ add to content """
            resource_nodes = ""
            
            for resource in note.resources:
                resource_nodes += '<en-media type="%s" hash="%s" />' % (resource.mime, resource.data.bodyHash)

            note.content = note.content.replace("</en-note>", resource_nodes + "</en-note>")

        logging.debug("New note : %s", note)

        return self.getNoteStore().createNote(self.authToken, note)
Exemple #8
0
    def updateTag(self, guid, name):
        tag = Types.Tag()
        tag.name = name
        tag.guid = guid

        logging.debug("Update tag : %s", tag)

        self.getNoteStore().updateTag(self.authToken, tag)
        return True
Exemple #9
0
    def updateNotebook(self, guid, name):
        notebook = Types.Notebook()
        notebook.name = name
        notebook.guid = guid

        logging.debug("Update notebook : %s", notebook)

        self.getNoteStore().updateNotebook(self.authToken, notebook)
        return True
Exemple #10
0
    def updateNotebook(self, guid, name):
        notebook = Types.Notebook()
        notebook.name = name
        notebook.guid = guid

        logging.debug("Update notebook : %s", notebook)

        self.getNoteStore().updateNotebook(self.authToken, notebook)
        return True
Exemple #11
0
    def updateTag(self, guid, name):
        tag = Types.Tag()
        tag.name = name
        tag.guid = guid

        logging.debug("Update tag : %s", tag)

        self.getNoteStore().updateTag(self.authToken, tag)
        return True
Exemple #12
0
    def _parseInput(self,
                    title=None,
                    content=None,
                    tags=None,
                    notebook=None,
                    resources=None,
                    note=None):
        result = {
            "title": title,
            "content": content,
            "tags": tags,
            "notebook": notebook,
            "resources": resources,
        }
        result = tools.strip(result)

        # if get note without params
        if note and title is None and content is None and tags is None and notebook is None:
            content = config.EDITOR_OPEN

        if title is None and note:
            result['title'] = note.title

        if content:
            content = Editor.textToENML(content, format='other')
            result['content'] = content
            '''
            if content != config.EDITOR_OPEN:
                if isinstance(content, str) and os.path.isfile(content):
                    logging.debug("Load content from the file")
                    content = open(content, "r").read()

                logging.debug("Convert content")
            '''

        if tags:
            result['tags'] = tools.strip(tags.split(','))

        if notebook:
            #notepadGuid = Notebooks().getNoteGUID(notebook)
            notepadGuid = self.getNoteGUID(notebook)
            if notepadGuid is None:
                #newNotepad = Notebooks().create(notebook)
                newNotepad = self.create(notebook)
                notepadGuid = newNotepad.guid

            result['notebook'] = notepadGuid
            logging.debug("Search notebook")

        return result
Exemple #13
0
    def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=None, note=None):
        result = {
            "title": title,
            "content": content,
            "tags": tags,
            "notebook": notebook,
            "resources": resources,
        }
        result = tools.strip(result)

        # if get note without params
        if note and title is None and content is None and tags is None and notebook is None:
            content = config.EDITOR_OPEN

        if title is None and note:
            result['title'] = note.title

        if content:
            content = Editor.textToENML(content,format='other')
            result['content'] = content
            '''
            if content != config.EDITOR_OPEN:
                if isinstance(content, str) and os.path.isfile(content):
                    logging.debug("Load content from the file")
                    content = open(content, "r").read()

                logging.debug("Convert content")
            '''

        if tags:
            result['tags'] = tools.strip(tags.split(','))

        if notebook:
            #notepadGuid = Notebooks().getNoteGUID(notebook)
            notepadGuid = self.getNoteGUID(notebook)
            if notepadGuid is None:
                #newNotepad = Notebooks().create(notebook)
                newNotepad = self.create(notebook)
                notepadGuid = newNotepad.guid

            result['notebook'] = notepadGuid
            logging.debug("Search notebook")

        return result
Exemple #14
0
    def removeNotebook(self, guid):
        logging.debug("Delete notebook : %s", guid)

        self.getNoteStore().expungeNotebook(self.authToken, guid)
        return True
Exemple #15
0
    def removeNote(self, guid):
        logging.debug("Delete note with guid: %s", guid)

        self.getNoteStore().deleteNote(self.authToken, guid)
        return True
Exemple #16
0
    def removeNotebook(self, guid):
        logging.debug("Delete notebook : %s", guid)

        self.getNoteStore().expungeNotebook(self.authToken, guid)
        return True
Exemple #17
0
    def removeTag(self, guid):
        logging.debug("Delete tag : %s", guid)

        self.getNoteStore().expungeTag(self.authToken, guid)
        return True
Exemple #18
0
    def removeNote(self, guid):
        logging.debug("Delete note with guid: %s", guid)

        self.getNoteStore().deleteNote(self.authToken, guid)
        return True
Exemple #19
0
    def removeTag(self, guid):
        logging.debug("Delete tag : %s", guid)

        self.getNoteStore().expungeTag(self.authToken, guid)
        return True
Exemple #20
0
    def createNote(self,
                   title,
                   content,
                   tags=None,
                   notebook=None,
                   created=None,
                   resources=None):
        def make_resource(filename):
            try:
                mtype = mimetypes.guess_type(filename)[0]

                if mtype.split('/')[0] == "text":
                    rmode = "r"
                else:
                    rmode = "rb"

                with open(filename, rmode) as f:
                    """ file exists """
                    resource = Types.Resource()
                    resource.data = Types.Data()

                    data = f.read()
                    md5 = hashlib.md5()
                    md5.update(data)

                    resource.data.bodyHash = md5.hexdigest()
                    resource.data.body = data
                    resource.data.size = len(data)
                    resource.mime = mtype
                    resource.attributes = Types.ResourceAttributes()
                    resource.attributes.fileName = os.path.basename(filename)
                    return resource
            except IOError:
                msg = "The file '%s' does not exist." % filename
                out.failureMessage(msg)
                raise IOError(msg)

        note = Types.Note()
        note.title = title
        note.content = content
        note.created = created

        if tags:
            note.tagNames = tags

        if notebook:
            note.notebookGuid = notebook

        if resources:
            """ make EverNote API resources """
            note.resources = map(make_resource, resources)
            """ add to content """
            resource_nodes = ""

            for resource in note.resources:
                resource_nodes += '<en-media type="%s" hash="%s" />' % (
                    resource.mime, resource.data.bodyHash)

            note.content = note.content.replace("</en-note>",
                                                resource_nodes + "</en-note>")

        logging.debug("New note : %s", note)

        return self.getNoteStore().createNote(self.authToken, note)
Exemple #21
0
 def checkAuth(self):
     self.authToken = self.getStorage().getUserToken()
     logging.debug("oAuth token : %s", self.authToken)
     if self.authToken:
         return True
     return False
Exemple #22
0
 def checkAuth(self):
     self.authToken = self.getStorage().getUserToken()
     logging.debug("oAuth token : %s", self.authToken)
     if self.authToken:
         return True
     return False