diff options
Diffstat (limited to 'module/plugins/hooks/CaptchaBrotherhood.py')
-rw-r--r-- | module/plugins/hooks/CaptchaBrotherhood.py | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index bda080037..0df1ab8a9 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -9,11 +9,12 @@ import urllib try: from PIL import Image + except ImportError: import Image -from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class CaptchaBrotherhoodException(Exception): @@ -22,7 +23,7 @@ class CaptchaBrotherhoodException(Exception): self.err = err - def getCode(self): + def get_code(self): return self.err @@ -37,11 +38,12 @@ class CaptchaBrotherhoodException(Exception): class CaptchaBrotherhood(Hook): __name__ = "CaptchaBrotherhood" __type__ = "hook" - __version__ = "0.08" + __version__ = "0.10" + __status__ = "testing" - __config__ = [("username", "str", "Username", ""), - ("force", "bool", "Force CT even if client is connected", False), - ("passkey", "password", "Password", "")] + __config__ = [("username" , "str" , "Username" , "" ), + ("password" , "password", "Password" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to CaptchaBrotherhood.com""" __license__ = "GPLv3" @@ -49,23 +51,17 @@ class CaptchaBrotherhood(Hook): ("zoidberg", "zoidberg@mujmail.cz")] - interval = 0 #@TODO: Remove in 0.4.10 - API_URL = "http://www.captchabrotherhood.com/" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def getCredits(self): - res = getURL(self.API_URL + "askCredits.aspx", - get={"username": self.getConfig('username'), "password": self.getConfig('passkey')}) + def get_credits(self): + res = self.load(self.API_URL + "askCredits.aspx", + get={'username': self.get_config('username'), 'password': self.get_config('password')}) if not res.startswith("OK"): raise CaptchaBrotherhoodException(res) else: credits = int(res[3:]) - self.logInfo(_("%d credits left") % credits) + self.log_info(_("%d credits left") % credits) self.info['credits'] = credits return credits @@ -74,7 +70,7 @@ class CaptchaBrotherhood(Hook): try: img = Image.open(captcha) output = StringIO.StringIO() - self.logDebug("CAPTCHA IMAGE", img, img.format, img.mode) + self.log_debug("CAPTCHA IMAGE", img, img.format, img.mode) if img.format in ("GIF", "JPEG"): img.save(output, img.format) else: @@ -86,11 +82,11 @@ class CaptchaBrotherhood(Hook): except Exception, e: raise CaptchaBrotherhoodException("Reading or converting captcha image failed: %s" % e) - req = getRequest() + req = get_request() url = "%ssendNewCaptcha.aspx?%s" % (self.API_URL, - urllib.urlencode({'username' : self.getConfig('username'), - 'password' : self.getConfig('passkey'), + urllib.urlencode({'username' : self.get_config('username'), + 'password' : self.get_config('password'), 'captchaSource': "pyLoad", 'timeout' : "80"})) @@ -122,50 +118,50 @@ class CaptchaBrotherhood(Hook): def api_response(self, api, ticket): - res = getURL("%s%s.aspx" % (self.API_URL, api), - get={"username": self.getConfig('username'), - "password": self.getConfig('passkey'), - "captchaID": ticket}) + res = self.load("%s%s.aspx" % (self.API_URL, api), + get={'username': self.get_config('username'), + 'password': self.get_config('password'), + 'captchaID': ticket}) if not res.startswith("OK"): raise CaptchaBrotherhoodException("Unknown response: %s" % res) return res - def newCaptchaTask(self, task): + def captcha_task(self, task): if "service" in task.data: return False if not task.isTextual(): return False - if not self.getConfig('username') or not self.getConfig('passkey'): + if not self.get_config('username') or not self.get_config('password'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False - if self.getCredits() > 10: + if self.get_credits() > 10: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(100) - self._processCaptcha(task) + self._process_captcha(task) else: - self.logInfo(_("Your CaptchaBrotherhood Account has not enough credits")) + self.log_info(_("Your CaptchaBrotherhood Account has not enough credits")) - def captchaInvalid(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: + def captcha_invalid(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: res = self.api_response("complainCaptcha", task.data['ticket']) @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) except CaptchaBrotherhoodException, e: - task.error = e.getCode() + task.error = e.get_code() return task.data['ticket'] = ticket |