Example #1
0
    def __init__(self, shape, train=7, val=1, test=2):
        self.labels = 17

        #   read data from cache or origin tgz
        cache = Cache('./cache/17flowers{}.pkl'.format(shape))
        self.data = cache.load()
        if not self.data:
            from IO import load_flowers17
            self.data = load_flowers17('./data/17flowers.tgz', shape)
            cache.save(self.data)

        path = './data/flowers17.pkl'
        if os.path.isfile(path):
            with open(path, 'rb') as f:
                self.train, self.val, self.test = pickle.load(f)
        else:
            self.train, self.val, self.test = \
                    Sample(), Sample(), Sample()
            self.split_data(train, val, test)

            self.train.to_np()
            self.val.to_np()
            self.test.to_np()
            with open(path, 'wb') as f:
                pickle.dump([self.train, self.val, self.test], f)
        self.train_list = range(len(self.train.image))
        self.val_list = range(len(self.val.image))
        self.test_list = range(len(self.test.image))
Example #2
0
    def login(self, url, success_judge, \
            certcode_url=None, cache_name='./data', anonymous=False, \
            **kwargs):
        from getpass import getpass
        _input = getpass if anonymous else input
        
        def get_certcode(url):
            print('[LOG] downloading certcode from %s ..' % url)
            name = 'certcode.jpg'
            certcode_path = os.path.join(self.cache_path, name)
            self.download(name, url)
            print('[LOG] try to import cv2..')
            try:
                import cv2
                img = cv2.imread(certcode_path)
                if 'recognition' in kwargs:
                    print('[LOG] use auto recognition instead!')
                    return kwargs['recognition'](img, kwargs['pattern'])
                print('[SUC] successfully import cv2. please watch the image window and input certcode..')
                cv2.imshow(cache_name, img)
                cv2.waitKey(3000)
            except:
                print('[ERR] failed to import cv2. please input certcode from %s' % certcode_path)
            certcode = str(input('[I N] certcode: '))
            return certcode

        print('[LOG] start to login %s ..' % url)
        information = Cache(cache_name)
        data = information.load('login')
        if not data:
            username = _input('[I N] username: '******'[I N] password: '******'[I N] tel: ')
            ####    ####    ####    ####
            #   change data format to what target website needs
            data = {
                'nickName': username,
                'password': password,
                'logintype': 'PLATFORM',
            }
            ####    ####    ####    ####
            information.save(tel, 'tel')
            information.save(data, 'login')
        certcode = get_certcode(certcode_url) if certcode_url else None

        ####    ####    ####    ####
        #   change data format to what target website needs
        if certcode:
            data['checkCode'] = certcode
        ####    ####    ####    ####

        print('[LOG] hi, user %s.' % (data['nickName'] \
                if not anonymous else 'anonymous'))

        response = self.post(url, data=data, headers=self.headers)
        self.html_save(response, 'login.html')

        
        return success_judge(response)