Example #1
0
    def getWordByName(self, wordName):
        try:
            data = self.dictionary[wordName].decode('utf-8', 'ignore')
        except KeyError, e:
            print u'未找到单词:%s' % "".join(e.message)
            return None
        else:
            if data[0] == '*':
                phonetic, interp = data.split('\n', 1)
                phonetic = phonetic[1:]
            else:
                phonetic = ""
                interp = data

            word = Word()
            word.name = wordName
            word.phonetic = phonetic
            word.interp = interp
            return word

    def getRandomWord(self):
        # 随机取词
        name = "".join(random.choice(self.dictionary.idx._idx.keys()))
        word = self.getWordByName(name)
        return word


class RecordManager:
    def __init__(self, recordPath, dictManager):
        self.recordPath = recordPath
        self.dictManager = dictManager