Beispiel #1
0
def test_note():
    b = 40
    c = 1

    note = NoteService.getChapterNote(b, c)
    print(note)

    gh = GitHubGist()
    gh.openGistChapterNote(b, c)
    print(gh.getUpdated())
Beispiel #2
0
 def getVerseNote(b, c, v):
     validGist = False
     noteL = noteG = None
     if config.enableGist:
         gh = GitHubGist()
         gh.openGistVerseNote(b, c, v)
         file = gh.getFile()
         if file:
             updatedG = gh.getUpdated()
             noteG = file.content
             validGist = True
     ns = NoteService.getNoteSqlite()
     noteL, updatedL = ns.displayVerseNote(b, c, v)
     validLocal = True
     if noteL == config.thisTranslation["empty"]:
         validLocal = False
     if validGist and not validLocal:
         note = noteG
     elif not validGist and validLocal:
         if config.enableGist:
             gh.updateContent(noteL, updatedL)
         note = noteL
     elif validGist and validLocal:
         if updatedL is None:
             note = NoteService.mergeNotes(noteL, noteG)
         elif updatedG > updatedL:
             note = noteG
         else:
             note = noteL
     else:
         note = noteL
     if noteG is not None and note == noteG:
         ns.saveVerseNote(b, c, v, noteG, updatedG)
     return note
Beispiel #3
0
 def saveVerseNote(b, c, v, note):
     now = DateUtil.epoch()
     if config.enableGist:
         gh = GitHubGist()
         gh.openGistVerseNote(b, c, v)
         gh.updateContent(note, now)
     ns = NoteService.getNoteSqlite()
     ns.saveVerseNote(b, c, v, note, now)
Beispiel #4
0
 def checkStatus(self):
     if len(self.gistTokenInput.text()) < 40:
         self.setStatus("Not connected", False)
         self.connected = False
     else:
         self.gh = GitHubGist(self.gistTokenInput.text())
         if self.gh.connected:
             self.setStatus("Connected to " + self.gh.user.name, True)
             self.connected = True
             config.gistToken = self.gistTokenInput.text()
         else:
             self.setStatus("Not connected", False)
             self.connected = False
     self.enableButtons()
Beispiel #5
0
    def run(self):
        gh = GitHubGist()
        gNotes = gh.getAllNoteGists()
        gists = {}
        if gNotes:
            for gist in gNotes:
                gists[gist.description] = gist
        ns = NoteService.getNoteSqlite()
        count = 0
        books = ns.getAllBooks()
        chapters = ns.getAllChapters()
        verses = ns.getAllVerses()
        notes = books + chapters + verses
        self.logger.debug("Uploading {0} notes".format(len(notes)))
        # Upload from local to Gist
        for note in notes:
            count += 1
            book = note[0]
            chapter = note[1]
            verse = note[2]
            contentL = note[3]
            updatedL = note[4]
            if chapter == 0:
                description = GitHubGist.bToBookName(book)
            elif verse == 0:
                description = GitHubGist.bcToChapterName(book, chapter)
            else:
                description = GitHubGist.bcvToVerseName(book, chapter, verse)
            msg = "Processing upload " + description + " ..."
            self.progress.emit(msg)
            self.logger.debug(msg)
            updateGistFile = False
            updated = DateUtil.epoch()
            gist = None
            if description in gists.keys():
                gist = gists[description]
            if gist is None:
                updateGistFile = True
            else:
                updatedG = GitHubGist.extractUpdated(gist)
                # if the local updated time is blank,  merge the local database file with the gist file
                if updatedL is None:
                    contentG = GitHubGist.extractContent(gist)
                    contentL = NoteService.mergeNotes(contentL, contentG, "---<br/>")
                    if chapter == 0:
                        ns.saveBookNote(book, contentL, updated)
                    elif verse == 0:
                        ns.saveChapterNote(book, chapter, contentL, updated)
                    else:
                        ns.saveVerseNote(book, chapter, verse, contentL, updated)
                    updateGistFile = True
                # if the updated time of local database note > gist time, then update gist
                elif updatedL > updatedG:
                    updateGistFile = True
                    updated = updatedL
                # if the local time <= gist time, then don't update gist
                elif updatedL <= updatedG:
                    updateGistFile = False
            if updateGistFile:
                msg = "Updating gist " + description
                self.logger.debug(msg)
                if chapter == 0:
                    gh.openGistBookNote(book)
                elif verse == 0:
                    gh.openGistChapterNote(book, chapter)
                else:
                    gh.openGistVerseNote(book, chapter, verse)
                gh.updateContent(contentL, updated)
        # Download from Gist
        gNotes = gh.getAllNoteGists()
        for gist in gNotes:
            count += 1
            msg = "Processing download " + gist.description + " ..."
            self.progress.emit(msg)
            self.logger.debug(msg)
            contentG = GitHubGist.extractContent(gist)
            updatedG = GitHubGist.extractUpdated(gist)
            if "Book" in gist.description:
                book = GitHubGist.bookNameToB(gist.description)
                chapter = 0
                verse = 0
                res = [note for note in books if note[0] == book]
            elif "Chapter" in gist.description:
                (book, chapter) = GitHubGist.chapterNameToBc(gist.description)
                verse = 0
                res = [note for note in chapters if note[0] == book and note[1] == chapter]
            elif "Verse" in gist.description:
                (book, chapter, verse) = GitHubGist.verseNameToBcv(gist.description)
                res = [note for note in verses if note[0] == book and note[1] == chapter and note[2] == verse]
            # if local note does not exist, then create local note
            if len(res) == 0:
                msg = "Creating local " + gist.description
                self.logger.debug(msg)
                if chapter == 0:
                    ns.saveBookNote(book, contentG, updatedG)
                elif verse == 0:
                    ns.saveChapterNote(book, chapter, contentG, updatedG)
                else:
                    ns.saveVerseNote(book, chapter, verse, contentG, updatedG)
            # if local note already exist
            else:
                noteL = res[0]
                updatedL = noteL[4]
                # if gist update time > local update time, then update local
                if updatedG > updatedL:
                    self.logger.debug("Updating local " + gist.description)
                    if chapter == 0:
                        ns.setBookNoteUpdate(book, contentG, updatedG)
                    elif verse == 0:
                        ns.setChapterNoteUpdate(book, chapter, contentG, updatedG)
                    else:
                        ns.setVerseNoteUpdate(book, chapter, verse, contentG, updatedG)

        self.finished.emit(count)
        self.logger.debug("Sync done")