Exemple #1
0
    def save_evaluation_practice_words(self, practiceMode, saveEnabled):
        _FUNC_NAME_ = "save_evaluation_practice_words"

        if saveEnabled:
            if len(self.activePracticeWords) > 0:

                if practiceMode.lower() == "test":
                    practiceFileName = SB_DATA_DIR + SB_PRACTICE_WORD_FILE
                    practiceFileName = practiceFileName.format(LISTID=self.contestList)
                elif practiceMode.lower() == "revise":
                    practiceFileName = SB_DATA_DIR + SB_REVISION_WORD_FILE

                currentPracticeWordList = []

                # Get previously saved practice words
                if os.path.isfile(practiceFileName) and os.path.getsize(practiceFileName) > 0:
                    currentPracticeWordList = cfile.read(practiceFileName).splitlines()                # Use of splitlines() avoids the newline character from being stored in the word list

                # Save practice words to practice file, if not already saved
                for word in self.activePracticeWords:
                    
                    DEBUG_VAR="word"
                    coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(word)))
                    coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))

                    practiceFileText = SB_EMPTY_STRING
                    if word not in currentPracticeWordList:
                        practiceFileText = practiceFileText + word + SB_NEWLINE

                if practiceFileText != SB_EMPTY_STRING:
                    cfile.append(practiceFileName, practiceFileText)
Exemple #2
0
                elif entryRowName == "Lang. of Origin":
                    wordEtymology = entryRowValue
                elif entryRowName == "Definition":
                    wordDefinition = entryRowValue
                elif entryRowName == "Examples":
                    wordExamples = entryRowValue
                    wordExamples = re.sub('[ ]*,[ ]*', APP_WORD_DELIMITER, wordExamples, flags=re.IGNORECASE)
                elif entryRowName == "Addl. Info":
                    wordNote = entryRowValue
                elif entryRowName == "Sentence":
                    wordSentence = entryRowValue
                elif entryRowName == "Related Words":
                    wordRelated = entryRowValue
                    wordRelated = re.sub('[ ]*,[ ]*', APP_WORD_DELIMITER, wordRelated, flags=re.IGNORECASE)
                elif entryRowName != APP_EMPTY_STRING:
                    cfile.append(APP_LIST_ERROR_FILE, "{};{}".format(displayWord, entryRowName))


            audioElement = browser.find_element_by_xpath("//audio[@id='audio1']")
            if audioElement is not None:
                wordAudioURL = audioElement.get_property("src")

            wordEntry = "#!Source: " + APP_SOURCE_DESC
            wordEntry = wordEntry + APP_NEWLINE + "#!Word: " + listWord
            wordEntry = wordEntry + APP_NEWLINE + "#!Respelling: " + wordRespelling
            wordEntry = wordEntry + APP_NEWLINE + "#!AudioURL: " + wordAudioURL
            wordEntry = wordEntry + APP_NEWLINE + "#!Etymology: " + wordEtymology
            wordEntry = wordEntry + APP_NEWLINE + "#!Sentence: " + wordSentence
            wordEntry = wordEntry + APP_NEWLINE + "#!Note: " + wordNote
            wordEntry = wordEntry + APP_NEWLINE + "#!Meta: " + wordMeta
            wordEntry = wordEntry + APP_NEWLINE + "#!Examples: " + wordExamples
Exemple #3
0
    def display_evaluation_result(self, practiceMode, saveResultEnabled, savePracticeEnabled):

        if practiceMode.lower() == "test":
            testHeader  = unicode("=============== Start of Test Log ===============", 'utf-8')
            testTrailer = unicode("================ End of Test Log ================", 'utf-8')
            testFileName = SB_DATA_DIR + SB_TEST_LOG

        elif practiceMode.lower() == "revise":
            testHeader  = unicode("=============== Start of Revision Log ===============", 'utf-8')
            testTrailer = unicode("================ End of Revision Log ================", 'utf-8')
            testFileName = SB_DATA_DIR + SB_REVISION_LOG
     
        # Test header
        testStats = SB_NEWLINE + unicode("Spelling Bee {0}".format(self.contestList), 'utf-8')
        testStats += SB_NEWLINE + unicode("Word Count [{0}] Chapter [{1}/{2}] Words [{3}-{4}]".format(self.word_count(), self.activeChapter, self.chapter_count(), self.activeRangeStart + 1, self.activeRangeEnd + 1), 'utf-8')
        testStats += SB_NEWLINE + SB_NEWLINE + unicode("Test Date [{0}] Score [{1}]".format(self.activeTestDate, self.activeTestScore), 'utf-8')

        displayText = testStats
        print displayText,

        logText = testHeader + testStats

        # Test valuations
        # Print colorized test valuations
        coloredTestValuations = []
        for valuation in self.activeTestValuations:
            if re.match('^' + SB_RIGHT_SYMBOL + '.*', valuation):
                textColor = coutput.get_term_color('green', 'normal', 'normal')
            else:
                textColor = coutput.get_term_color('red', 'normal', 'normal')
            coloredTestValuations.append(textColor + valuation + coutput.get_term_color('normal', 'normal', 'normal'))

        print SB_NEWLINE,
        coutput.print_columnized_list(coloredTestValuations, SB_COLUMN_COUNT)

        columnizedTestValuations = coutput.columnize(self.activeTestValuations, SB_COLUMN_COUNT)
        for row in columnizedTestValuations:
            logText += SB_NEWLINE
            for col in row:
                logText += col

        # Test practice words
        if len(self.activePracticeWords) > 0:
            practiceWordsText = SB_NEWLINE + unicode("Practice Words:", 'utf-8')
            for row in coutput.columnize(self.activePracticeWords, SB_COLUMN_COUNT):
                practiceWordsText += SB_NEWLINE
                for col in row:
                    practiceWordsText += col
                
            print practiceWordsText,

            logText += SB_NEWLINE + practiceWordsText

        # Test trailer
        logText += SB_NEWLINE + testTrailer + SB_NEWLINE

        if saveResultEnabled:
            # Save practice words
            self.save_evaluation_practice_words(practiceMode, savePracticeEnabled)

            # Save test log
            cfile.append(testFileName, logText)
Exemple #4
0
    def lookup_dictionary_by_word(self, word):
        _FUNC_NAME_ = "lookup_dictionary_by_word"

        DEBUG_VAR="self.wordList[0]"
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(self.wordList[0])))
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))

        DEBUG_VAR="word"
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(word)))
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))

        self.activeWord = word.strip()

        DEBUG_VAR="self.activeWord"
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(self.activeWord)))
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))
        
        # Setup connection and error logging
        connectionPool = urllib3.PoolManager(10, headers=SB_USER_AGENT)
        errorFileName = SB_DATA_DIR + SB_ERR_LOG

        # Check offline for dictionary entry
        self.activeEntry = SB_EMPTY_STRING
        self.activeDefinition = []

        overrideDefnFileName = SB_DICT_OVERRIDE_DIR + SB_DICT_OVERRIDE_DEFN.format(WORD=word).replace(" ", "_")
        offlineEntryFileName = SB_DICT_OFFLINE_DIR + SB_DICT_OFFLINE_ENTR.format(WORD=word).replace(" ", "_")

        # Check for dictionary definition override
        if os.path.isfile(overrideDefnFileName) and os.path.getsize(overrideDefnFileName) > 0:
            self.activeEntry = unicode("[Dictionary Definition Override]", 'utf-8')
            self.activeDefinition = cfile.read(overrideDefnFileName).splitlines()

            DEBUG_VAR="self.activeEntry"
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(self.activeEntry)))
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))

        # Check primary source for dictionary entry
        elif os.path.isfile(offlineEntryFileName) and os.path.getsize(offlineEntryFileName) > 100:
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "offlineEntryFile size :: {0}".format(os.path.getsize(offlineEntryFileName)))
            self.activeEntry = cfile.read(offlineEntryFileName)
            self.activeDefinition = cdict.parse_word_definition(self.activeWord, self.activeEntry)

            DEBUG_VAR="self.activeEntry"
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(self.activeEntry)))
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))

        else:
            # Download dictionary entry
            self.activeEntry = cdict.get_dictionary_entry(connectionPool, self.activeWord)

            DEBUG_VAR="self.activeEntry"
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "{0} :: {1}".format(DEBUG_VAR, type(self.activeEntry)))
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, eval(DEBUG_VAR))

            # Save dictionary entry offline
            cfile.write(offlineEntryFileName, self.activeEntry)

            # Retrieve word definition
            self.activeDefinition = cdict.parse_word_definition(self.activeWord, self.activeEntry)
            if len(self.activeDefinition) == 0:
                # Log missing definition error
                errorText = unicode("ERROR:Missing Definition:{0}\n", 'utf-8')
                errorText = errorText.format(self.activeWord)
                cfile.append(errorFileName, errorText)

        # Check offline for word pronunciation
        self.activePronunciation = SB_EMPTY_STRING
        self.activePronunciationWord = SB_EMPTY_STRING

        overrideProncnFileName = SB_DICT_OVERRIDE_DIR + SB_DICT_OVERRIDE_CLIP.format(WORD=self.activeWord).replace(" ", "_")
        offlineProncnFileName = SB_DICT_OFFLINE_DIR + SB_DICT_OFFLINE_CLIP.format(WORD=self.activeWord).replace(" ", "_")

        # Check for dictionary pronunciation override
        if os.path.isfile(overrideProncnFileName) and os.path.getsize(overrideProncnFileName) > 0:
            self.activePronunciation = overrideProncnFileName
            self.activePronunciationWord = self.activeWord

        # Check primary source for dictionary entry and pronunciation
        elif os.path.isfile(offlineEntryFileName) and os.path.getsize(offlineEntryFileName) > 100 and os.path.isfile(offlineProncnFileName) and os.path.getsize(offlineProncnFileName) > 1000:
            coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "offlineProncnFile size :: {0}".format(os.path.getsize(offlineProncnFileName)))

            self.activePronunciation = offlineProncnFileName

            # Retrieve pronunciation audio clip word form and filename
            [wordClipForm, wordClipURL] = cdict.parse_word_clip(self.activeWord, self.activeEntry)
            self.activePronunciationWord = wordClipForm

        else:
            # Retrieve pronunciation audio clip word form and filename
            [wordClipForm, wordClipURL] = cdict.parse_word_clip(self.activeWord, self.activeEntry)

            # Save pronunciation offline
            if wordClipURL == SB_EMPTY_STRING:
                # Log missing audio error
                errorText = unicode("ERROR:Missing Audio:{0}\n", 'utf-8')
                errorText = errorText.format(self.activeWord)
                cfile.append(errorFileName, errorText)
            else:
                # Download audio clip
                cfile.download(connectionPool, wordClipURL, offlineProncnFileName)

                self.activePronunciation = offlineProncnFileName
                self.activePronunciationWord = wordClipForm

        # Log audio mismatch error
        wordToken = re.sub('[^a-zA-Z]', SB_EMPTY_STRING, self.activeWord.lower())
        pronunciationToken = re.sub('[^a-zA-Z]', SB_EMPTY_STRING, self.activePronunciationWord.lower())
        if self.activePronunciation != SB_EMPTY_STRING and wordToken != pronunciationToken:
            errorText = unicode("ERROR:Audio Mismatch:{0}\n", 'utf-8')
            errorText = errorText.format(self.activeWord)
            cfile.append(errorFileName, errorText)

        # Close connection
        connectionPool.clear()
    if SDO_ERR_AUDIO_REGEX_PATTERN.match(logValues[2]):
        coutput.print_watcher(SB_ERR_DEBUG, _FUNC_NAME_, 'wordEntry[4]')
        if wordEntry[4] != "":
            print ">> Downloaded pronunciation override"
            cfile.download(connectionPool, wordEntry[4], SDO_OVERRIDE_PRON_FILE.format(WORD=word))
        else:
            SDO_ERR_CLIP_MISSING = True
            coutput.print_color('yellow', "WARNING: Pronunciation override not available")

    # Log errors
    errorText = unicode("ERROR:{0}:", 'utf-8').format(word)
    if SDO_ERR_DEFN_MISSING:
        errorText += unicode(">Definition Missing", 'utf-8')
    if SDO_ERR_CLIP_MISSING:
        errorText += unicode(">Audio Missing", 'utf-8')
    
    if errorText != unicode("ERROR:{0}:", 'utf-8').format(word):
        errorText += unicode("\n", 'utf-8')
        cfile.append(SDO_LOG_FILE, errorText)

connectionPool.clear()


########################################################################
# Debugging Commands
########################################################################
'''
cd $PROJ
sudo python spellit_download_log_overrides.py
'''
Exemple #6
0
            print("\n>>>>>>>>>> {} Fetching entry rows ...".format(wordIndex))

            entryRows = browser.find_elements_by_xpath(
                "//div[@class='table-responsive']/table/tbody/tr")

            setWord = APP_COLLECTION_CATEGORY

            for row in entryRows:
                entryCols = row.find_elements_by_tag_name("td")

                if len(entryCols) == 0:
                    continue
                elif len(entryCols) != 7:
                    cfile.append(
                        APP_LIST_ERROR_FILE, "Unexpected Columns:{}:{}".format(
                            len(entryCols), row.text.strip()))
                    continue

                displayWord = ''
                listWord = ''
                keyWord = ''
                wordMeta = ''

                wordRespelling = ''
                wordAudioURL = ''
                wordFuncLabel = ''
                wordEtymology = ''
                wordDefinition = ''
                wordExamples = ''
                wordNote = ''