Loads a captcha and decrypts it with ocr, plugin, user input :param url: url of captcha image :param get: get part for request :param post: post part for request :param cookies: True if cookies should be enabled :param forceUser: if True, ocr is not used
(self, url, get={}, post={}, cookies=False, forceUser=False, imgtype='jpg',
result_type='textual')
| 327 | self.cTask.correct() |
| 328 | |
| 329 | def decryptCaptcha(self, url, get={}, post={}, cookies=False, forceUser=False, imgtype='jpg', |
| 330 | result_type='textual'): |
| 331 | """ Loads a captcha and decrypts it with ocr, plugin, user input |
| 332 | |
| 333 | :param url: url of captcha image |
| 334 | :param get: get part for request |
| 335 | :param post: post part for request |
| 336 | :param cookies: True if cookies should be enabled |
| 337 | :param forceUser: if True, ocr is not used |
| 338 | :param imgtype: Type of the Image |
| 339 | :param result_type: 'textual' if text is written on the captcha\ |
| 340 | or 'positional' for captcha where the user have to click\ |
| 341 | on a specific region on the captcha |
| 342 | |
| 343 | :return: result of decrypting |
| 344 | """ |
| 345 | |
| 346 | img = self.load(url, get=get, post=post, cookies=cookies) |
| 347 | |
| 348 | id = ("%.2f" % time())[-6:].replace(".", "") |
| 349 | temp_file = open(join("tmp", "tmpCaptcha_%s_%s.%s" % (self.__name__, id, imgtype)), "wb") |
| 350 | temp_file.write(img) |
| 351 | temp_file.close() |
| 352 | |
| 353 | has_plugin = self.__name__ in self.core.pluginManager.captchaPlugins |
| 354 | |
| 355 | if self.core.captcha: |
| 356 | Ocr = self.core.pluginManager.loadClass("captcha", self.__name__) |
| 357 | else: |
| 358 | Ocr = None |
| 359 | |
| 360 | if Ocr and not forceUser: |
| 361 | sleep(randint(3000, 5000) / 1000.0) |
| 362 | if self.pyfile.abort: raise Abort |
| 363 | |
| 364 | ocr = Ocr() |
| 365 | result = ocr.get_captcha(temp_file.name) |
| 366 | else: |
| 367 | captchaManager = self.core.captchaManager |
| 368 | task = captchaManager.newTask(img, imgtype, temp_file.name, result_type) |
| 369 | self.cTask = task |
| 370 | captchaManager.handleCaptcha(task) |
| 371 | |
| 372 | while task.isWaiting(): |
| 373 | if self.pyfile.abort: |
| 374 | captchaManager.removeTask(task) |
| 375 | raise Abort |
| 376 | sleep(1) |
| 377 | |
| 378 | captchaManager.removeTask(task) |
| 379 | |
| 380 | if task.error and has_plugin: #ignore default error message since the user could use OCR |
| 381 | self.fail(_("Pil and tesseract not installed and no Client connected for captcha decrypting")) |
| 382 | elif task.error: |
| 383 | self.fail(task.error) |
| 384 | elif not task.result: |
| 385 | self.fail(_("No captcha result obtained in appropiate time by any of the plugins.")) |
| 386 |
nothing calls this directly
no test coverage detected