Example #1
0
    def test_part_two_examples(self):
        """Test Chaptcha examples for Part Two"""

        # 1. Loop for the examples
        for enum, text in enumerate(P2_EXAMPLES):

            # 2. Create the Captcha object
            mycap = captcha.Captcha(part2=True, text=text)

            # 3. Check methods
            self.assertEqual(mycap.solve(verbose=False), P2_SOLUTIONS[enum])
Example #2
0
    def test_part_one_examples(self):
        """Test Chaptcha examples for Part One"""

        # 1. Loop for the examples
        for enum, text in enumerate(P1_EXAMPLES):

            # 2. Create the Captcha object
            mycap = captcha.Captcha(text=text)

            # 3. Check methods
            self.assertEqual(mycap.solve(verbose=False), P1_SOLUTIONS[enum])
            self.assertEqual(mycap.re_solve(verbose=False), P1_SOLUTIONS[enum])
Example #3
0
    def test_text_init(self):
        """Test Captcha object creation from text"""

        # 1. Create Captcha object from text
        mycap = captcha.Captcha(text=aoc_01.from_text(P1_EXAMPLE_TEXT)[0])

        # 2. Make sure it has the specified values
        self.assertEqual(mycap.text, "1122")
        self.assertEqual(mycap.part2, False)
        self.assertEqual(mycap.offset, 1)

        # 3. Check methods
        self.assertEqual(mycap.solve(), 3)
        self.assertEqual(mycap.re_solve(), 3)
Example #4
0
    def test_value_init(self):
        "Test Captcha object creation with values"

        # 1. Create Captcha object with values
        mycap = captcha.Captcha(text="1122", offset=1)

        # 2. Make sure it has the specified values
        self.assertEqual(mycap.text, "1122")
        self.assertEqual(mycap.part2, False)
        self.assertEqual(mycap.offset, 1)

        # 3. Check methods
        self.assertEqual(mycap.solve(), 3)
        self.assertEqual(mycap.re_solve(), 3)
Example #5
0
    def test_empty_init(self):
        """Test default Captcha object creation"""

        # 1. Create default Captcha object
        mycap = captcha.Captcha()

        # 2. Make sure it has the default values
        self.assertEqual(mycap.text, None)
        self.assertEqual(mycap.part2, False)
        self.assertEqual(mycap.offset, 1)

        # 3. Check methods
        self.assertEqual(mycap.solve(), None)
        self.assertEqual(mycap.re_solve(), None)
Example #6
0
    def test_part_two_text_init(self):
        """Test Captcha object creation from text"""

        # 1. Create Captcha object from text
        mycap = captcha.Captcha(part2=True,
                                text=aoc_01.from_text(P2_EXAMPLE_TEXT)[0])

        # 2. Make sure it has the specified values
        self.assertEqual(mycap.text, "1212")
        self.assertEqual(mycap.part2, True)
        self.assertEqual(mycap.offset, 2)

        # 3. Check methods
        self.assertEqual(mycap.solve(verbose=False), 6)
Example #7
0
    def __init__(self, account_id, password, douban_id, hotReload=False):
        self.ck = None

        #turing
        self.turi = turibot.chat_turi()
        #redis
        self.redis = redis.StrictRedis(host='localhost', port=redis_port, password='******')    

        #itchat thread
        self.capt_queue = queue.Queue(1)
        self.sofa_queue = queue.Queue()

        self.captcha = captcha.Captcha()
        #wait input 间隔
        self.captcha_last = time.time()
        #发送邮件间隔
        self.mail_interval = 0
        #自动识别失败次数
        self.mail_fail = 0

        self.sofa_dic = {}
        self.doumail_dic = {}
        self.notify_dic = {}
        self.temp_ignore = {}

        #douban robot
        self.douban_id = str(douban_id)
        self.account_id = account_id
        self.password = password
        self.data = {
                "form_email": self.account_id,
                "form_password": self.password,
                "source": "index_nav",
                "remember": "on",
                "user_login": "******"
                }
        self.session = requests.Session()
        self.login_url = 'https://www.douban.com/accounts/login'

        self.session.headers = {
                "Connection": "keep-alive",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
                "Origin": "https://www.douban.com",
                }
        # self.session.headers = self.headers
        if not hotReload:
            self.login()
        elif self.load_cookies():
            self.get_ck(None)
Example #8
0
	def __init__(self, config_path):
		self._config = config.Config(config_path)

		self._database = database.Database(self._config.db_connection_string)

		self._captcha = captcha.Captcha(self._config.captcha_secret)
		self._currency = currency.Currency(self._config.currency_cache, self._config.fixer_apikey)
		self._geoip = geoip.GeoIpCountry(self._config.geoip_datafile)
		self._mail = mail.Mail(self._config.email_user, self._config.email_password, self._config.email_smtp, self._config.email_from, self._config.email_sender_name)

		with self._database.connect() as db:
			entities.load(db)

		self._ip_address = None

		self.automation_mode = False
Example #9
0
import captcha

from captcha import captcha, CapDisplay

disp = CapDisplay.CapDisplay(1200, 800)

allLetter = 'ABCDEFGHKLMNPRSTUVWXYZabcdefghklmnprstuvwyz23456789'
print len(allLetter)
for i in range(len(allLetter)):
    leng = 4
    if allLetter[i] == 'A' or allLetter[i] == 'f' or allLetter[i] == 'W':
        leng = 1
    cap = captcha.Captcha(1, 1, allLetter[i], leng)
    while cap.failure == 1:
        cap = captcha.Captcha(1, 1, allLetter[i], leng)

    disp.update_segs(cap.get_segments())
    disp.display_cap()
    disp.display_seg()

Example #10
0
import captcha

from captcha import captcha, CapDisplay

disp = CapDisplay.CapDisplay(1200, 800)

letter = "sS"
leng = 4
while True:
    cap = captcha.Captcha(1, 1, letter, leng)
    while cap.failure == 1:
        cap = captcha.Captcha(1, 1, letter, leng)

    disp.update_segs(cap.get_segments())
    disp.display_cap()
    disp.display_seg()