diff --git a/modules/ebonics/module.py b/modules/ebonics/module.py index d57939c3bb2dcc596a70fb15305212a90e343d25..480c40c51d21460b4aaa71161e4299c09fdae14d 100644 --- a/modules/ebonics/module.py +++ b/modules/ebonics/module.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2012 Romain Bignon +# Copyright(C) 2012-2018 Romain Bignon, Laurent Bachelier # # This file is part of weboob. # @@ -18,16 +18,29 @@ # along with weboob. If not, see . - -from weboob.capabilities.translate import CapTranslate, Translation, TranslationFail, LanguageNotSupported +from weboob.browser import URL, PagesBrowser +from weboob.browser.filters.html import FormValue +from weboob.browser.pages import HTMLPage +from weboob.capabilities.translate import CapTranslate, LanguageNotSupported, Translation, TranslationFail from weboob.tools.backend import Module -from weboob.tools.compat import urlencode -from weboob.deprecated.browser import StandardBrowser - __all__ = ['EbonicsModule'] +class TranslatorPage(HTMLPage): + def get_text(self): + return FormValue('//textarea[@name="Ebonics"]')(self.doc) + + +class Ebonics(PagesBrowser): + translator = URL('http://joel.net/EBONICS/Translator', TranslatorPage) + + def translate(self, text): + return self.open(self.translator.build(), + data={'English': text}, + data_encoding='UTF-8').page.get_text() + + class EbonicsModule(Module, CapTranslate): NAME = 'ebonics' MAINTAINER = u'Romain Bignon' @@ -35,26 +48,19 @@ class EbonicsModule(Module, CapTranslate): VERSION = '1.4' LICENSE = 'AGPLv3+' DESCRIPTION = u'English to Ebonics translation service' - BROWSER = StandardBrowser + BROWSER = Ebonics 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', urlencode(data)) - try: - text = doc.getroot().cssselect('div.translateform div.bubble1 div.bubblemid')[0].text - except IndexError: - raise TranslationFail() - - if text is None: + translated_text = self.browser.translate(text) + if not translated_text: raise TranslationFail() translation = Translation(0) - translation.lang_src = unicode(lan_from) - translation.lang_dst = unicode(lan_to) - translation.text = unicode(text).strip() + translation.lang_src = lan_from + translation.lang_dst = lan_to + translation.text = translated_text return translation diff --git a/tools/py3-compatible.modules b/tools/py3-compatible.modules index 1acdb058ad1f39ed41de4f130852fca9053b0b43..9086df541be7a8fc5e96a812afb26c974b22181d 100644 --- a/tools/py3-compatible.modules +++ b/tools/py3-compatible.modules @@ -34,6 +34,7 @@ creditdunord/ cuisineaz/ delubac/ dlfp/ +ebonics/ entreparticuliers/ erehsbc/ esalia/