예제 #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 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