Esempio n. 1
0
class RecognizeCaptcha(AntiGate):
    captcha_file = 'captcha.png'

    def __init__(self):
        self.conf = Conf()
        self.conf.read_section('antigate')

        super().__init__(auto_run=False, **self.conf.namespace)

    def crop_image(self, image_path, captcha_size):
        image = Image.open(image_path)
        image.crop(captcha_size).save(self.captcha_file)

    def _balance(self):
        balanse = super().balance()
        if logger:
            logger.info("Balance: {}".format(balanse))
        if balanse < 1:
            raise RuntimeWarning('Out of balance!!!')

    def recognize(self, image: str, rect: 'element rect'):
        try:
            self.balance()
        except RuntimeWarning:
            return None

        captcha_size = (rect['x'],
                        rect['y'],
                        rect['width'] + rect['x'] - 1,
                        rect['height'] + rect['y'] - 1)

        self.crop_image(image, captcha_size)
        super().run(self.captcha_file)
Esempio n. 2
0
try:
    from config import Conf
except ImportError:
    from .Defaults import DefaultConf as Conf

__author__ = 'whoami'
__version__ = '2.4.1'
__date__ = '27.03.16 0:46'
__description__ = """
Обертка для selenium.webdriver
"""


config = Conf()
config.read_section('webdriver')


class SwithSuperMetaclass(type):
    """
    Метакласс для подметы класса родителя для класса WebDriver.
    """

    def __new__(cls, name, bases, dct):
        if cls.web_driver_select():
            bases = webdriver.PhantomJS,
        else:
            bases = webdriver.Firefox,

        return type.__new__(cls, name, bases, dct)
Esempio n. 3
0
# -*- coding: utf-8 -*-
from pyvirtualdisplay import Display
from config import Conf

conf = Conf()
conf.read_section('base')


class SingletonMetaclass(type):
    """
    Метаксласс для разовой инициализации класса Logger и возврата
    объекта логгера
    """
    def __init__(cls, *args, **kw):
        cls.instance = None

    def __call__(cls, *args, **kw):
        if cls.instance is None:
            cls.instance = super(
                SingletonMetaclass, cls).__call__(*args, **kw)
        return cls.instance


class VirtualDisplay(metaclass=SingletonMetaclass):
    display = None
    trigger = int(conf.use_virtual_display)

    def __init__(self):
        if not self.trigger:
            return
Esempio n. 4
0
import inspect
import os

from os.path import isfile
from datetime import datetime
from config import Conf

__author__ = 'whoami'
__version__ = '1.0.1'
__date__ = '27.03.16 0:46'
__description__ = """
Оборачиваем работу проекта в лог
"""

config = Conf()
config.read_section('logger')


def get_class_variable_state(fun):
    def wrapper(cls):
        head_line = '*' * 5 + ' {0} varible state '.format(cls.__class__) + '*' * 5
        foter_line = '*' * len(head_line)
        body_line = ''
        dct = dict(map(lambda x: (x, getattr(cls, x)),
                       filter(lambda x: '__' not in x and isinstance(getattr(cls, x), (tuple, list, int, str, set, dict)),
                              cls.__dir__())))
        for key in dct:
            body_line += '{0} : {1}\n'.format(key, dct[key])

        return '\n{0}\n{1}\n{2}'.format(head_line, body_line, foter_line)