Пример #1
0
Файл: ecc.py Проект: re1ard/ecc
class anticaptcha:
	gate = None
	processing = False

	def __init__(self,agkey):
		self.gate = AntiGate(agkey)
		print 'good shit'
		print 'antigate balance: ' + str(self.gate.balance())
		return None

	def captchasolution(self,error):
		link = "./captcha_directory/"+str(time.time())+".jpg"
		urllib.urlretrieve(error.get_url(), link)
		print 'captcha loaded to directory: ' + link
		sid = self.gate.send(link)
		print 'done... lets begin to solution'
		key = self.gate.get(sid)
		print 'ok... this code: ' + key
		os.rename("./captcha_directory/"+key+".jpg")
		return key

	def solution(self,error):
		if self.processing:
			while self.processing:
				time.sleep(3)
			return True,0
			
		else:
			self.processing = True
			id = error.try_again(self.captchasolution(error))
			self.processing = False
			return False,id
Пример #2
0
def error_happens(response, current, params):
    print "===================ERROR=============================="
    print response
    print "===================ERROR END=========================="
    response = response['error']
    if response['error_code'] == 14: #Captcha needed
        os.popen("curl '%s' > captcha1.jpg" %response['captcha_img'])
        gate = AntiGate(config.ANTICAPCHA_KEY, auto_run=False)
        captcha1 = gate.send('captcha1.jpg')
        captcha =  gate.get(captcha1)
        print captcha
        time.sleep(90.0)
        # print "Введи капчу!"
        # captcha = sys.stdin.readline()
        # captcha = captcha.split('\n')[0]
        # print captcha
        params += [('captcha_sid ', response['captcha_sid']), ('captcha_key', captcha)]
        method = ''
        for para in response['request_params']:
            if para['key'] == 'method':
                method = para['value']
            else:
                pass
        r = call_api(method, params, current['token'])
        print r
        return r
    else:
        print "Дело не в капче!\n", response['error_msg']
        return 
Пример #3
0
    def test_manual_binary(self):
        gate = AntiGate(API_KEY, auto_run=False)

        captcha_id = gate.send(open(IMAGE1, 'rb').read(), binary=True)
        self.assertTrue(str(captcha_id).isdigit())

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #4
0
    def test_manual_binary(self):
        gate = AntiGate(API_KEY, auto_run=False)

        captcha_id = gate.send(open(IMAGE1, 'rb').read(), binary=True)
        self.assertTrue(str(captcha_id).isdigit())

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #5
0
    def test_manual(self):
        gate = AntiGate(API_KEY, auto_run=False)

        captcha_id = gate.send(IMAGE1)
        self.assertTrue(str(captcha_id).isdigit())

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #6
0
    def test_manual(self):
        gate = AntiGate(API_KEY, auto_run=False)

        captcha_id = gate.send(IMAGE1)
        self.assertTrue(str(captcha_id).isdigit())

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #7
0
    def test_manual_base64(self):
        gate = AntiGate(API_KEY, auto_run=False)
        fp = open(IMAGE1, 'rb')
        captcha_id = gate.send(fp.read())
        self.assertTrue(str(captcha_id).isdigit())
        fp.close()

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #8
0
    def test_manual_base64(self):
        gate = AntiGate(API_KEY, auto_run=False)
        fp = open(IMAGE1, 'rb')
        captcha_id = gate.send(fp.read())
        self.assertTrue(str(captcha_id).isdigit())
        fp.close()

        captcha_value = gate.get(captcha_id)
        self.assertEqual(str(captcha_value), '123')
Пример #9
0
def solve_captcha(img):

    while True:
        try:
            gate = AntiGate(key)
            captcha_id = gate.send(img)
            answer = (gate.get(captcha_id))
            return (answer)

        except AntiGateError as error:
            print(error)
            break
Пример #10
0
def get_captcha_answer(captcha_url):
    captcha_name = 'captcha.jpg'

    img_data = requests.get(captcha_url).content
    with open(captcha_name, 'wb') as handler:
        handler.write(img_data)

    gate = AntiGate('90f2971a20beee5a508bad796a8790fa')
    captcha_id = gate.send(captcha_name)
    print('Расшифровываем капчу')
    result = gate.get(captcha_id)
    print('Расшифровали капчу: %s' % result)
    return result
Пример #11
0
class AG:
    def __init__(self):
        self.gate = AntiGate(config.ag_key)
        self.answer = ''

    def captcha_solve(self, url):
        with open('image.jpg', 'wb') as image:
            image.write(urlopen(url).read())
        self.answer = self.gate.send('image.jpg')
        return self.gate.get(self.answer)

    def abuse(self):
        self.gate.abuse()
Пример #12
0
def captcha_handler(captcha):

    config = get_auth()
    api_key = config.get('antigate', 'api_key')

    cap_img = captcha.get_image()
    print('Разгадываю капчу..')

    gate = AntiGate(api_key)
    captcha_id1 = gate.send(cap_img)
    key = gate.get(captcha_id1)
    print('Разгадал! Тут написанно:', key, 'Ввожу..')

    # Пробуем снова отправить запрос с капчей
    return captcha.try_again(key)
Пример #13
0
    def main_func(self):
            pyautogui.click(x=771, y=573)
            is_ok = False
            while is_ok!=True:
                if self.status != STOP:
                    sleep(5)
                    pyautogui.moveTo(x=100, y=100)
                    self.driver.save_screenshot('/home/myroslav/reserv/reserv/visareserv/screenshot/screed/1'+'.png')

                    from PIL import Image
                    test_image = "/home/myroslav/reserv/reserv/visareserv/screenshot/screed/1.png"
                    original = Image.open(test_image)
                    box = (569, 89, 982, 596)
                    cropped_example = original.crop(box)
                    cropped_example.save("/home/myroslav/reserv/reserv/visareserv/screenshot/res/1.png", 'png')

                    from antigate import AntiGate
                    gate = AntiGate('AntiGatePass')
                    captcha_id = gate.send("/home/myroslav/reserv/reserv/visareserv/screenshot/res/1.png")
                    result = gate.get(captcha_id)
                    print result
                    if result:
                        all_number = self.get_number_image(result)
                        print "all_number", all_number
                        coordinate = self.get_coordinate(all_number)
                        print "coordinate", coordinate
                        self.click_on_image(coordinate)
                        pyautogui.click(x=954, y=706)
                        pyautogui.moveTo(710, 657, 3, pyautogui.easeInOutQuad)
                        pyautogui.click(x=710, y=657)

                        text = self.driver.find_element_by_xpath('//*[@id="cp1_lblNoDates"]').text
                        print text
                        print self.driver.find_element_by_xpath('//*[@id="cp1_lblNoDatesEmbassyInfo"]').text
                        #We are sorry, but no free slots are available. Try to register later.
                        # [2016-02-19 00:05:09,402: WARNING/Worker-5] 2/19/2016 12:05:12 AM UTC, Ukraine () - Kyjev, Long-term residence permit

                        if "We are sorry" in text:
                            pyautogui.moveTo(685, 439, 3, pyautogui.easeInOutQuad)
                            pyautogui.click(x=685, y=439)
                            sleep(2)
                            obj = DateCheckerBase(company=self, text=text, free_date=None)
                            obj.save()
                            self.main_func()
                        else:
                            is_ok = True
                            obj = DateCheckerBase(company=self, text=text, free_date=None)
                            obj.save()
Пример #14
0
def solve_captcha(image):
    from antigate import AntiGate, AntiGateError

    sent = False
    while not sent:
        try:
            gate = AntiGate('.')
            captcha_id = gate.send(image)
            answer = (gate.get(captcha_id))
            return (answer)

        except AntiGateError as error:
            import _email
            logger.error('<ERROR: %s>' % error)
            _email.send('CAPTCHA', error, " ")
            break
Пример #15
0
    def captcha_send(self, img_bit):
        """
        Принемает картинку ->
        Отправляет её на "анти капчу" ->
        и отдает результат

        :param img_bit: картинка в виде бинарной строки
        :return: результат распознания
        """
        try:
            captcha_gate = AntiGate('35c9e83daa70e28958154736d1621d2e')  # TODO убрать данные
            captcha_id = captcha_gate.send(img_bit)

            captcha = captcha_gate.get(captcha_id)

            logger.info('captcha_gate get: {}'.format(captcha))

            return captcha
        except Exception as err:
            # logger.warning(err)
            return None
Пример #16
0
def solve_captcha(img_filename, is_russian=True):
    gate_config = {'is_russian': int(is_russian)}
    cap_text = AntiGate(KEY_ANTIGATE, img_filename, send_config=gate_config)
    return cap_text.get()
from antigate import AntiGate
gate = AntiGate('40207091f8f58a38c3bb136b5a8688fe')

idsFile = 'ids.txt'
solutionsFile = 'solutions.txt'

for i in range(1, 2000):
    captcha_id = gate.send('../samples/' + str(i) + '.png')
    with open(idsFile, 'a') as f:
        f.write(str(i) + '\t' + captcha_id + '\n')

    solved = gate.get(captcha_id)
    solved = solved.replace("\n", "")
    solved = solved.replace("\t", "")

    with open(solutionsFile, 'a') as f:
        f.write(str(i) + '\t' + solved + '\n')
Пример #18
0
 def test_load(self):
     load = AntiGate(API_KEY).load()
     self.assertTrue(len(load) > 0)
     self.assertEqual(type(load), OrderedDict)
     self.assertTrue(load.get('load') is not None)
Пример #19
0
    def solve(self, driver, limit_log=False):
        self.captcha_type = "recaptcha"  # could also be "text"
        done = False
        """
        Find captcha widget
        """
        found_widget = self.find_widget(driver, limit_log)
        if not found_widget:
            print "didnt find widget"
            return False
        """
        Find captcha popup
        """
        self.find_popup(driver, limit_log)
        """ STRESS TESTING
        test_input = raw_input("continue?")
        if not "y" in test_input:
            return False
        """

        if not limit_log:
            self.pmaster.log("doing challenge")
        done_challenge = False
        done_challenge_tries = 0

        while not done_challenge:
            print "inside while"
            if done_challenge_tries > self.max_try:
                return False
            try:
                """
                Get string challenge, table type and captcha image
                """
                self.challenge_str = driver.find_element_by_class_name(
                    "rc-imageselect-desc-no-canonical").text
                if not limit_log:
                    self.pmaster.log("challenge is '" + self.challenge_str +
                                     "'")
                """
                Gets table object and defines self.type
                """
                self.table = self.get_captcha_table(driver)
                #if self.type == "4x4":
                #if not limit_log:
                #self.pmaster.log("captcha is 4x4, exiting and will start again (if retry is > 1)")
                #return False
                """
                Gets full image to send to 2captcha
                """
                self.image_src = self.get_captcha_image(driver)

                done_challenge = True
            except:
                done_challenge_tries += 1

                # try if captcha is only text response
                try:
                    self.image_src = self.get_captcha_image(driver,
                                                            type="text")
                    self.captcha_type = "text"

                    self.captcha_text_answer = driver.find_element_by_id(
                        'default-response')
                    done_challenge = True
                except:
                    done_challenge_tries += 1
                    print "error: getting challenge image and string"
                    if not limit_log:
                        self.pmaster.log(
                            "error: getting challenge image and string")
                    done_challenge = False
        """
        Save image to /tmp/ folder
        """
        try:
            # save image
            resource = urllib.urlopen(self.image_src)
            self.dir_captcha_image = "tmp/captcha_" + str(
                random.randint(10000, 99999)) + ".jpg"
            output = open(self.dir_captcha_image, "wb")
            output.write(resource.read())
            output.close()

            if self.type == "4x4":
                outfile = self.dir_captcha_image
                size = (600, 600)
                try:
                    im = Image.open(outfile)
                    new_img = im.resize(size)
                    new_img.save(outfile, "JPEG")
                except IOError:
                    print "cannot create 600px img for '%s'" % outfile
                except Exception as e:
                    print "exception creating 600px img for 4x4 catpchas: " + str(
                        e)

        except Exception as e:
            print "Exception ocurred while saving image: " + str(e)
            return False
        """
        Captchas API's access
        """
        #if self.type != "4x4":
        if True:

            try:
                """
                2Captcha API
                """
                if self.captcha_api_service == "2captcha":

                    captcha2upload = CaptchaUpload(self.api_key)
                    self.service = captcha2upload
                    #self.log.warn("2captcha balance = "+captcha2upload.getbalance())

                    self.captcha_result = captcha2upload.solve(
                        self.dir_captcha_image,
                        text=self.challenge_str,
                        type=self.type)
                    print "data returned 2captcha = " + str(
                        self.captcha_result)
                    self.credit_used += 1

                    # couldnt solve
                    if self.captcha_result == 1:
                        self.pmaster.log(
                            "Captcha service couldn't find a solution")
                        self.report_bad_answer()
                        return False
                    else:
                        captcha_answer = True
                """
                Antigate API
                """
                if self.captcha_api_service == "antigate":

                    antigate = AntiGate(str(self.api_key))
                    self.service = antigate
                    #self.log.warn("antigate balance = "+str(antigate.balance()))

                    captcha_id = antigate.send(self.dir_captcha_image)
                    self.captcha_result = antigate.get(captcha_id)
                    print "data returned antigate = " + str(
                        self.captcha_result)
                    self.credit_used += 1

                    captcha_answer = True

                    self.clean_captcha_img()
                """
                ImageTyperz API
                """
                if self.captcha_api_service == "imagetyperz":

                    imagetyperz = ImageTyperz(self.api_user, self.api_pass)
                    self.service = imagetyperz
                    #self.log.warn("imagetyperz balance = "+imagetyperz.get_balance())

                    self.captcha_result = imagetyperz.solve(
                        self.dir_captcha_image)
                    print "data returned by imagetyperz = " + self.captcha_result
                    self.credit_used += 1

                    captcha_answer = True

                    self.clean_captcha_img()

            except AntiGateError:
                print "could not send captcha to Antigate"
                self.pmaster.log("could not send captcha to Antigate")

            except Exception as e:
                print "could not send captcha to" + self.captcha_api_service + "api = " + str(
                    e)
                self.pmaster.log("could not send captcha to " +
                                 self.captcha_api_service + " api = " + str(e))

        else:
            print "not trying 4x4 types...goodbye"
            if not limit_log:
                self.pmaster.log("4x4 captchas not supported")
            return False

        #if self.type != "4x4" and captcha_answer:
        if captcha_answer:
            if not limit_log:
                self.pmaster.log("answering captcha")
            ans = self.answer_captcha(driver, self.captcha_result)
            if ans:
                done = True

        return done
Пример #20
0
import time
from antigate import AntiGate            # AntiCaptcha

n = 1
while n<8:
    start = time.clock()
   # print AntiGate('888fe7041b163b35255dddafe49bfe6c', "/home/myroslav/reserv/reserv/visareserv/screenshot/res/%d.png" % n) # AntiCaptcha('API-KEY', 'captcha.jpg')
    print "n = %d" %n
    gate = AntiGate('888fe7041b163b35255dddafe49bfe6c')               # AntiCaptcha('API-KEY')
    captcha_id = gate.send("/home/myroslav/reserv/reserv/visareserv/screenshot/res/%d.png" % n)
    print gate.get(captcha_id)
    end = time.clock()
    n+=1
    interval = end - start
    print "interval =", interval
Пример #21
0
 def test_load(self):
     load = AntiGate(API_KEY).load()
     self.assertTrue(len(load) > 0)
     self.assertEqual(type(load), OrderedDict)
     self.assertTrue(load.get('load') is not None)
Пример #22
0
def get_captcha(captcha_path):
    gate = AntiGate(settings.ANTIGATE_API_KEY, captcha_path)
    return gate.get(gate.captcha_id)