예제 #1
0
파일: module.py 프로젝트: dermorz/weboob
    def translate(self, lan_from, lan_to, text):
        if lan_from != 'English' or lan_to != 'Nigger!':
            raise LanguageNotSupported()

        with self.browser:
            data = {'English': text.encode('utf-8')}
            doc = self.browser.location('http://joel.net/EBONICS/Translator',
                                        urllib.urlencode(data))
            try:
                text = doc.getroot().cssselect(
                    'div.translateform div.bubble1 div.bubblemid')[0].text
            except IndexError:
                raise TranslationFail()

        if text is None:
            raise TranslationFail()

        translation = Translation(0)
        translation.lang_src = unicode(lan_from)
        translation.lang_dst = unicode(lan_to)
        translation.text = unicode(text).strip()

        return translation