def generate_override(self): """ #!Source: <Name of source> #!Respelling: <Respelling> #!AudioURL: <URL of pronunciation audio> #!Etymology: <Language of origin> #!Sentence: <Sentence> #!Note: <Note> #!Meta: <Metadata> (<Part of speech>) <Definition> """ override = [] if self.source != DICT_UNICODE_EMPTY_STR: override.append("#!Source: " + self.source) if self.respelling is not None: override.append("#!Respelling: " + self.respelling.text) if self.pronunciation is not None: override.append("#!AudioURL: " + self.pronunciation.audio_url) if self.etymology != DICT_UNICODE_EMPTY_STR: override.append("#!Etymology: " + self.etymology) override = override + self.definitions return coutput.multiline_text(override)
cleansedText = cparser.cleanse_text(listRawText, SB_CLEAN_TEXT_PATTERNS, SB_CLEAN_INNER_TEXT_PATTERNS, SB_CLEAN_OUTER_TEXT_PATTERNS) listLang = listID.lower().replace(' ', '-') # Process basic word list listType = "basic" listFileName = SB_WORD_LIST_OUT[args.contestYear].format(YEAR=listYear, SEQ=listSeq, LANG=listLang, TYPE=listType) sectionOuterTextPatterns = [ [r'.*<div class="section word study">', r'</div>.*'] ] sectionText = cparser.cleanse_text(cleansedText, SB_CLEAN_TEXT_PATTERNS, SB_CLEAN_INNER_TEXT_PATTERNS, sectionOuterTextPatterns) words = cparser.find_enclosed_text(r'<li>\s*', r'\s*</li>', sectionText) print "Writing " + listFileName cfile.write(listFileName, coutput.multiline_text(words)) # Process challenge word list listType = "challenge" listFileName = SB_WORD_LIST_OUT[args.contestYear].format(YEAR=listYear, SEQ=listSeq, LANG=listLang, TYPE=listType) sectionOuterTextPatterns = [ [r'.*<div class="section word challenge">', r'</div>.*'] ] sectionText = cparser.cleanse_text(cleansedText, SB_CLEAN_TEXT_PATTERNS, SB_CLEAN_INNER_TEXT_PATTERNS, sectionOuterTextPatterns) words = cparser.find_enclosed_text(r'<li>\s*', r'\s*</li>', sectionText) print "Writing " + listFileName cfile.write(listFileName, coutput.multiline_text(words)) connectionPool.clear()
logValues = entry.split(':') word = logValues[1] wordEntry = cdict.fetch_dictionary_entry(connectionPool, word) coutput.print_watcher(SB_ERR_DEBUG, _FUNC_NAME_, 'wordEntry') SDO_ERR_DEFN_MISSING = False SDO_ERR_CLIP_MISSING = False print unicode("Word: {0}\t{1}", 'utf-8').format(word, logValues[2]) if SDO_ERR_DEFN_REGEX_PATTERN.match(logValues[2]): coutput.print_watcher(SB_ERR_DEBUG, _FUNC_NAME_, 'wordEntry[1]') if len(wordEntry[1]) > 0: print ">> Downloaded definition override" cfile.write(SDO_OVERRIDE_DEFN_FILE.format(WORD=word), coutput.multiline_text(wordEntry[1])) else: SDO_ERR_DEFN_MISSING = True coutput.print_color('yellow', "WARNING: Definition override not available") 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)
################################################################ # Main Program ################################################################ connectionPool = urllib3.PoolManager(10, headers=SDO_USER_AGENT) wordList = cfile.read(SDO_CONF_FILE).splitlines() print u"Downloading overrides ..." for word in wordList: print u"Word: " + word wordEntry = cdict.fetch_dictionary_entry(connectionPool, word) if len(wordEntry[1]) > 0: cfile.write(SDO_OVERRIDE_DEFN_FILE.format(WORD=word), coutput.multiline_text(wordEntry[1])) else: coutput.print_color('yellow', "WARNING: Definition override not available") if wordEntry[4] != "": cfile.download(connectionPool, wordEntry[4], SDO_OVERRIDE_PRON_FILE.format(WORD=word)) else: coutput.print_color('yellow', "WARNING: Pronunciation override not available") connectionPool.clear() ######################################################################## # Debugging Commands ########################################################################
################################################################ # Main Program ################################################################ connectionPool = urllib3.PoolManager(10, headers=SDO_USER_AGENT) wordList = cfile.read(SDO_CONF_FILE).splitlines() print u"Downloading overrides ..." for word in wordList: print u"Word: " + word wordEntry = cdict.fetch_dictionary_entry(connectionPool, word) if len(wordEntry[1]) > 0: cfile.write(SDO_OVERRIDE_DEFN_FILE.format(WORD=word), coutput.multiline_text(wordEntry[1])) else: coutput.print_color('yellow', "WARNING: Definition override not available") if wordEntry[4] != "": cfile.download(connectionPool, wordEntry[4], SDO_OVERRIDE_PRON_FILE.format(WORD=word)) else: coutput.print_color('yellow', "WARNING: Pronunciation override not available") connectionPool.clear() ######################################################################## # Debugging Commands ######################################################################## '''