Exemple #1
0
 def test_set_note_attribute(self):
     data = {}
     attr = EvernoteMgr.set_note_attribute(data)
     self.assertTrue(type(attr) is bool)
     data = {'link': 'http://localhost'}
     attr = EvernoteMgr.set_note_attribute(data)
     self.assertTrue(type(attr) is not bool)
Exemple #2
0
    def _notebook(trigger, note_store):
        """
        :param trigger: trigger object
        :param note_store: note_store object
        :return: note object
        """
        note = Types.Note()
        if trigger.notebook:
            # get the notebookGUID ...
            notebook_id = EvernoteMgr.get_notebook(note_store,
                                                   trigger.notebook)
            # create notebookGUID if it does not exist then return its id
            note.notebookGuid = EvernoteMgr.set_notebook(
                note_store, trigger.notebook, notebook_id)

            if trigger.tag:
                # ... and get the tagGUID if a tag has been provided
                tag_id = EvernoteMgr.get_tag(note_store, trigger.tag)
                if tag_id is False:
                    tag_id = EvernoteMgr.set_tag(note_store, trigger.tag,
                                                 tag_id)
                    # set the tag to the note if a tag has been provided
                    if tag_id:
                        note.tagGuids = tag_id

            logger.debug("notebook that will be used %s", trigger.notebook)
        return note
Exemple #3
0
    def _notebook(trigger, note_store):
        """
        :param trigger: trigger object
        :param note_store: note_store object
        :return: note object
        """
        note = Types.Note()
        if trigger.notebook:
            # get the notebookGUID ...
            notebook_id = EvernoteMgr.get_notebook(note_store,
                                                   trigger.notebook)
            # create notebookGUID if it does not exist then return its id
            note.notebookGuid = EvernoteMgr.set_notebook(note_store,
                                                         trigger.notebook,
                                                         notebook_id)

            if trigger.tag:
                # ... and get the tagGUID if a tag has been provided
                tag_id = EvernoteMgr.get_tag(note_store,
                                             trigger.tag)
                if tag_id is False:
                    tag_id = EvernoteMgr.set_tag(note_store,
                                                 trigger.tag,
                                                 tag_id)
                    # set the tag to the note if a tag has been provided
                    note.tagGuids = tag_id

            logger.debug("notebook that will be used %s", trigger.notebook)
        return note
Exemple #4
0
 def test_set_note_attribute(self):
     data = {}
     attr = EvernoteMgr.set_note_attribute(data)
     self.assertTrue(type(attr) is bool)
     data = {'link': 'http://localhost'}
     attr = EvernoteMgr.set_note_attribute(data)
     self.assertTrue(type(attr) is not bool)
Exemple #5
0
    def get_evernote_notes(self, evernote_filter):
        """
            get the notes related to the filter
            :param evernote_filter: filtering
            :return: notes
        """
        data = []

        note_store = self.client.get_note_store()
        our_note_list = note_store.\
            findNotesMetadata(self.token, evernote_filter,
                              0, 100, EvernoteMgr.set_evernote_spec())

        for note in our_note_list.notes:
            whole_note = note_store.getNote(self.token,
                                            note.guid,
                                            True,
                                            True,
                                            False,
                                            False)
            content = self._cleaning_content(whole_note.content)
            data.append(
                {'title': note.title,
                 'my_date': arrow.get(note.created),
                 'link': whole_note.attributes.sourceURL,
                 'content': content})

        return data
Exemple #6
0
    def set_note_filter(filter_string):
        """

        :param filter_string:
        :return: note filter object
        """
        return EvernoteMgr.set_note_filter(filter_string)
Exemple #7
0
    def set_note_filter(filter_string):
        """

        :param filter_string:
        :return: note filter object
        """
        return EvernoteMgr.set_note_filter(filter_string)
Exemple #8
0
 def _content(note, content):
     """
     content of the note
     :param note: note object
     :param content: content string to make the main body of the note
     :return:
     """
     note.content = EvernoteMgr.set_header()
     note.content += sanitize(content)
     return note
Exemple #9
0
 def _content(note, content):
     """
     content of the note
     :param note: note object
     :param content: content string to make the main body of the note
     :return:
     """
     note.content = EvernoteMgr.set_header()
     note.content += sanitize(content)
     return note
Exemple #10
0
 def _attributes(note, data):
     """
     attribute of the note
     :param note: note object
     :param data:
     :return:
     """
     # attribute of the note: the link to the website
     note_attribute = EvernoteMgr.set_note_attribute(data)
     if note_attribute:
         note.attributes = note_attribute
     return note
Exemple #11
0
 def _footer(trigger, data, content):
     """
     footer of the note
     :param trigger: trigger object
     :param data: data to be used
     :param content: add the footer of the note to the content
     :return: content string
     """
     # footer of the note
     footer = EvernoteMgr.set_note_footer(data, trigger)
     content += footer
     return content
Exemple #12
0
 def _attributes(note, data):
     """
     attribute of the note
     :param note: note object
     :param data:
     :return:
     """
     # attribute of the note: the link to the website
     note_attribute = EvernoteMgr.set_note_attribute(data)
     if note_attribute:
         note.attributes = note_attribute
     return note
Exemple #13
0
 def _footer(trigger, data, content):
     """
     footer of the note
     :param trigger: trigger object
     :param data: data to be used
     :param content: add the footer of the note to the content
     :return: content string
     """
     # footer of the note
     footer = EvernoteMgr.set_note_footer(data, trigger)
     content += footer
     return content
Exemple #14
0
    def get_evernote_notes(self, evernote_filter):
        """
            get the notes related to the filter
            :param evernote_filter: filtering
            :return: notes
        """
        data = []

        note_store = self.client.get_note_store()
        our_note_list = note_store.findNotesMetadata(self.token, evernote_filter, 0, 100,
                                                     EvernoteMgr.set_evernote_spec())

        for note in our_note_list.notes:
            whole_note = note_store.getNote(self.token, note.guid, True, True, False, False)
            content = self._cleaning_content(whole_note.content)
            data.append({'title': note.title, 'my_date': arrow.get(note.created),
                         'link': whole_note.attributes.sourceURL, 'content': content})

        return data
Exemple #15
0
    def save_data(self, trigger_id, **data):
        """
            let's save the data
            don't want to handle empty title nor content
            otherwise this will produce an Exception by
            the Evernote's API

            :param trigger_id: trigger ID from which to save data
            :param data: the data to check to be used and save
            :type trigger_id: int
            :type data:  dict
            :return: the status of the save statement
            :rtype: boolean
        """
        # set the title and content of the data
        title, content = super(ServiceEvernote, self).save_data(trigger_id,
                                                                **data)

        # get the evernote data of this trigger
        trigger = Evernote.objects.get(trigger_id=trigger_id)
        # initialize notestore process
        note_store = self._notestore(trigger_id, data)
        if isinstance(note_store, evernote.api.client.Store):
            # note object
            note = self._notebook(trigger, note_store)
            # its attributes
            note = self._attributes(note, data)
            # its footer
            content = self._footer(trigger, data, content)
            # its title
            note.title = title if len(title) <= 255 else title[:255]
            # its content
            note = self._content(note, content)
            # create a note
            return EvernoteMgr.create_note(note_store, note,
                                           trigger_id, data)
        else:
            # so its note an evernote object, so something wrong happens
            return note_store
Exemple #16
0
    def save_data(self, trigger_id, **data):
        """
            let's save the data
            don't want to handle empty title nor content
            otherwise this will produce an Exception by
            the Evernote's API

            :param trigger_id: trigger ID from which to save data
            :param data: the data to check to be used and save
            :type trigger_id: int
            :type data:  dict
            :return: the status of the save statement
            :rtype: boolean
        """
        # set the title and content of the data
        title, content = super(ServiceEvernote, self).save_data(trigger_id,
                                                                **data)

        # get the evernote data of this trigger
        trigger = Evernote.objects.get(trigger_id=trigger_id)
        # initialize notestore process
        note_store = self._notestore(trigger_id, data)
        if isinstance(note_store, evernote.api.client.Store):
            # note object
            note = self._notebook(trigger, note_store)
            # its attributes
            note = self._attributes(note, data)
            # its footer
            content = self._footer(trigger, data, content)
            # its title
            note.title = title if len(title) <= 255 else title[:255]
            # its content
            note = self._content(note, content)
            # create a note
            return EvernoteMgr.create_note(note_store, note,
                                           trigger_id, data)
        else:
            # so its note an evernote object, so something wrong happens
            return note_store
Exemple #17
0
 def test_set_header(self):
     header = EvernoteMgr.set_header()
     self.assertTrue('DOCTYPE en-note SYSTEM "http://xml.evernote.'
                     'com/pub/enml2.dtd' in header)
Exemple #18
0
 def test_set_header(self):
     header = EvernoteMgr.set_header()
     self.assertTrue('DOCTYPE en-note SYSTEM "http://xml.evernote.'
                     'com/pub/enml2.dtd' in header)