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)
def __init_model(self): start = time.time() Conf.log.debug("Loading GAN Model For {}".format(self._phase)) # Create Model self.__model = DeepModel() self.__model.initialize(Conf(), self._gpu_ids, self._checkpoint) Conf.log.debug("Model load done in {} seconds".format(round(time.time() - start, 2)))
def __init__(self): self.conf = Conf() self.conf.read_section('antigate') super().__init__(auto_run=False, **self.conf.namespace)
#!/usr/bin/env python2.7 from config import Conf import tweepy if __name__ == '__main__': config = Conf("config") #config.printConf() auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret) auth.set_access_token(config.access_token, config.access_token_secret) api = tweepy.API(auth) print api.me().name #api.update_status("hello world") l = api.home_timeline() last_id = config.last_id last = 0 if config.last_id == '': last = 0 else: last = int(config.last_id) config.last_id = l[0].id_str try: tweets = open("tweets.txt", 'a') except IOError: print "can't open %s to write" % tweets for e in l: if int(e.id_str) > last: tweets.write(e.author.name + ":\t" + e.text) config.saveConf()
# -*- 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
from .Defaults import DefaultLogger as Logger 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)
import logging 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)