예제 #1
0
 def upload_validated_notes(self, automated=False):
     db = ankDB(TABLES.NOTE_VALIDATION_QUEUE)
     dbRows = db.all("validation_status = 1")
     notes_created, notes_updated, queries1, queries2 = ([] for i in range(4))
     """
     :type: (list[EvernoteNote], list[EvernoteNote], list[str], list[str])
     """
     noteFetcher = EvernoteNoteFetcher()
     tmr = stopwatch.Timer(len(dbRows), 25, infoStr="Upload of Validated Evernote Notes", automated=automated,
                           enabled=EVERNOTE.UPLOAD.ENABLED, max_allowed=EVERNOTE.UPLOAD.MAX,
                           label='Validation\\upload_validated_notes\\', display_initial_info=True)
     if tmr.actionInitializationFailed:
         return tmr.status, 0, 0
     for dbRow in dbRows:
         entry = EvernoteValidationEntry(dbRow)
         evernote_guid, rootTitle, contents, tagNames, notebookGuid, noteType = entry.items()
         tagNames = tagNames.split(',')
         if not tmr.checkLimits():
             break
         whole_note = tmr.autoStep(
             self.evernote.makeNote(rootTitle, contents, tagNames, notebookGuid, guid=evernote_guid,
                                    noteType=noteType, validated=True), rootTitle, evernote_guid)
         if tmr.report_result is False:
             raise ValueError
         if tmr.status.IsDelayableError:
             break
         if not tmr.status.IsSuccess:
             continue
         if not whole_note.tagNames:
             whole_note.tagNames = tagNames
         noteFetcher.addNoteFromServerToDB(whole_note, tagNames)
         note = EvernoteNotePrototype(whole_note=whole_note)
         assert whole_note.tagNames
         assert note.Tags
         if evernote_guid:
             notes_updated.append(note)
             queries1.append([evernote_guid])
         else:
             notes_created.append(note)
             queries2.append([rootTitle, contents])
     else:
         tmr.reportNoBreak()
     tmr.Report(self.anki.add_evernote_notes(notes_created) if tmr.counts.created else 0,
                self.anki.update_evernote_notes(notes_updated) if tmr.counts.updated else 0)
     if tmr.counts.created.completed.subcount:
         db.executemany("DELETE FROM {t} WHERE title = ? and contents = ? ", queries2)
     if tmr.counts.updated.completed.subcount:
         db.executemany("DELETE FROM {t} WHERE guid = ? ", queries1)
     if tmr.is_success:
         db.commit()
     if tmr.should_retry:
         create_timer(30 if tmr.status.IsDelayableError else EVERNOTE.UPLOAD.RESTART_INTERVAL,
                      self.upload_validated_notes, True)
     return tmr.status, tmr.count, 0
예제 #2
0
    def create_evernote_notes(self, evernote_guids=None, use_local_db_only=False):
        """
        Create EvernoteNote objects from Evernote GUIDs using EvernoteNoteFetcher.getNote().
        Will prematurely return if fetcher.getNote fails

        :rtype : EvernoteNoteFetcherResults
        :param evernote_guids:
        :param use_local_db_only: Do not initiate API calls
        :return: EvernoteNoteFetcherResults
        """
        if not hasattr(self, 'evernote_guids') or evernote_guids:
            self.evernote_guids = evernote_guids
        if not use_local_db_only:
            self.check_ancillary_data_up_to_date()
        action_str_base = 'Create'
        action_str = 'Creation Of'
        info = stopwatch.ActionInfo(action_str, 'Evernote Notes', report_if_empty=False)
        tmr = stopwatch.Timer(evernote_guids, info=info,
                              label='Add\\Evernote-%sNotes' % (action_str_base))
        fetcher = EvernoteNoteFetcher(self, use_local_db_only=use_local_db_only)
        if not evernote_guids:
            fetcher.results.Status = EvernoteAPIStatus.EmptyRequest; return fetcher.results
        if in_anki():
            fetcher.evernoteQueryTags = SETTINGS.EVERNOTE.QUERY.TAGS.fetch().replace(',', ' ').split()
            fetcher.keepEvernoteTags = SETTINGS.ANKI.TAGS.KEEP_TAGS.fetch()
            fetcher.deleteQueryTags = SETTINGS.ANKI.TAGS.DELETE_EVERNOTE_QUERY_TAGS.fetch()
            fetcher.tagsToDelete = SETTINGS.ANKI.TAGS.TO_DELETE.fetch().replace(',', ' ').split()
        for evernote_guid in self.evernote_guids:
            if not fetcher.getNote(evernote_guid):
                return fetcher.results
            tmr.reportSuccess()
            tmr.step(fetcher.result.Note.FullTitle)
        tmr.Report()
        return fetcher.results
예제 #3
0
    def create_evernote_notes(self,
                              evernote_guids=None,
                              use_local_db_only=False):
        """
        Create EvernoteNote objects from Evernote GUIDs using EvernoteNoteFetcher.getNote().
        Will prematurely return if fetcher.getNote fails

        :rtype : EvernoteNoteFetcherResults
        :param evernote_guids:
        :param use_local_db_only: Do not initiate API calls
        :return: EvernoteNoteFetcherResults
        """
        if not hasattr(self, 'evernote_guids') or evernote_guids:
            self.evernote_guids = evernote_guids
        if not use_local_db_only:
            self.check_ancillary_data_up_to_date()
        action_str_base = 'Create'
        action_str = 'Creation Of'
        info = stopwatch.ActionInfo(action_str,
                                    'Evernote Notes',
                                    report_if_empty=False)
        tmr = stopwatch.Timer(evernote_guids,
                              info=info,
                              label='Add\\Evernote-%sNotes' %
                              (action_str_base))
        fetcher = EvernoteNoteFetcher(self,
                                      use_local_db_only=use_local_db_only)
        if not evernote_guids:
            fetcher.results.Status = EvernoteAPIStatus.EmptyRequest
            return fetcher.results
        if in_anki():
            fetcher.evernoteQueryTags = SETTINGS.EVERNOTE.QUERY.TAGS.fetch(
            ).replace(',', ' ').split()
            fetcher.keepEvernoteTags = SETTINGS.ANKI.TAGS.KEEP_TAGS.fetch()
            fetcher.deleteQueryTags = SETTINGS.ANKI.TAGS.DELETE_EVERNOTE_QUERY_TAGS.fetch(
            )
            fetcher.tagsToDelete = SETTINGS.ANKI.TAGS.TO_DELETE.fetch(
            ).replace(',', ' ').split()
        for evernote_guid in self.evernote_guids:
            if not fetcher.getNote(evernote_guid):
                return fetcher.results
            tmr.reportSuccess()
            tmr.step(fetcher.result.Note.FullTitle)
        tmr.Report()
        return fetcher.results
예제 #4
0
 def upload_validated_notes(self, automated=False):
     db = ankDB(TABLES.NOTE_VALIDATION_QUEUE)
     dbRows = db.all("validation_status = 1")
     notes_created, notes_updated, queries1, queries2 = ([]
                                                         for i in range(4))
     """
     :type: (list[EvernoteNote], list[EvernoteNote], list[str], list[str])
     """
     noteFetcher = EvernoteNoteFetcher()
     tmr = stopwatch.Timer(len(dbRows),
                           25,
                           infoStr="Upload of Validated Evernote Notes",
                           automated=automated,
                           enabled=EVERNOTE.UPLOAD.ENABLED,
                           max_allowed=EVERNOTE.UPLOAD.MAX,
                           label='Validation\\upload_validated_notes\\',
                           display_initial_info=True)
     if tmr.actionInitializationFailed:
         return tmr.status, 0, 0
     for dbRow in dbRows:
         entry = EvernoteValidationEntry(dbRow)
         evernote_guid, rootTitle, contents, tagNames, notebookGuid, noteType = entry.items(
         )
         tagNames = tagNames.split(',')
         if not tmr.checkLimits():
             break
         whole_note = tmr.autoStep(
             self.evernote.makeNote(rootTitle,
                                    contents,
                                    tagNames,
                                    notebookGuid,
                                    guid=evernote_guid,
                                    noteType=noteType,
                                    validated=True), rootTitle,
             evernote_guid)
         if tmr.report_result is False:
             raise ValueError
         if tmr.status.IsDelayableError:
             break
         if not tmr.status.IsSuccess:
             continue
         if not whole_note.tagNames:
             whole_note.tagNames = tagNames
         noteFetcher.addNoteFromServerToDB(whole_note, tagNames)
         note = EvernoteNotePrototype(whole_note=whole_note)
         assert whole_note.tagNames
         assert note.Tags
         if evernote_guid:
             notes_updated.append(note)
             queries1.append([evernote_guid])
         else:
             notes_created.append(note)
             queries2.append([rootTitle, contents])
     else:
         tmr.reportNoBreak()
     tmr.Report(
         self.anki.add_evernote_notes(notes_created)
         if tmr.counts.created else 0,
         self.anki.update_evernote_notes(notes_updated)
         if tmr.counts.updated else 0)
     if tmr.counts.created.completed.subcount:
         db.executemany("DELETE FROM {t} WHERE title = ? and contents = ? ",
                        queries2)
     if tmr.counts.updated.completed.subcount:
         db.executemany("DELETE FROM {t} WHERE guid = ? ", queries1)
     if tmr.is_success:
         db.commit()
     if tmr.should_retry:
         create_timer(
             30 if tmr.status.IsDelayableError else
             EVERNOTE.UPLOAD.RESTART_INTERVAL, self.upload_validated_notes,
             True)
     return tmr.status, tmr.count, 0