示例#1
0
 def _request(self, url, params={}):
     # 应该使用统一的request函数去请求,此处待重构
     try:
         response = self.session.get(url, headers=FOLLOWER_HEADER, params=params, timeout=10)
         return response
     except requests.ConnectionError, requests.ConnectTimeout:
         logger.error('%s请求超时')
def main():
    parser = argparse.ArgumentParser(description='EOSIO testcase collections running tool.')
    parser.add_argument('--config', default="./config.json", type=str, help='config.json config file path')
    args = parser.parse_args()
    conf_file = os.path.abspath(os.path.expanduser(args.config))
    # Check the parameters
    if not os.path.exists('testcases'):
        logger.error('call startmonster.py in the eostestmonster directory')
        sys.exit(1)

    conf_dict = None
    with open(conf_file, 'r') as fp:
        conf_dict = json.loads(fp.read())
    if not conf_dict:
        logger.error('validator config can not be empty: {}'.format(conf_file))
        sys.exit(1)
    if not check_exist_acct(conf_dict):
        logger.error('ERROR: the exist_account is NOT available')
        sys.exit(1)

    setup_env()

    # Start the testcase
    try:
        time_start = time.time()
        result = run_monster(conf_dict)
        if not result:
            logger.error('!!! Call testcases FAILED !!!')
        else:
            logger.info('Call testcases SUCCESS !!!')
        time_usage = time.time() - time_start
        logger.info('TIME USAGE:%ss' % (time_usage,))
        return result
    except Exception as e:
        logger.error(traceback.print_exc())
示例#3
0
 def get_followers(self, uid):
     size = 1000
     url = urljoin(BASE_URL, FOLLOWERS_URL)
     params = {
         'size': size,
         'pageNo': 1,
         'uid': uid,
         '_': int(time.time() * 1000)
     }
     respond = self._request(url, params=params)
     if not respond:
         return []
     data = respond.json()
     max_page = data.get('maxPage')
     if not max_page:
         logger.error("获取粉丝失败")
         logger.error(data)
         raise ValueError("获取粉丝失败")
     result = data['followers']
     for page in range(1, max_page):
         time.sleep(FOLLOWER_PAGE_INTEVAL)
         logger.info('开始抓取第%s页的粉丝' % page)
         params['pageNo'] = page
         params['_'] = int(time.time() * 1000)
         respond = self._request(url, params=params)
         if not respond:
             continue
         data = respond.json()
         result += data['followers']
     return self.handle_followers(result)
示例#4
0
 def get_people_id(self, path):
     url = urljoin(BASE_URL, path)
     respond = self.session.get(url, headers=BASE_HEADER)
     if respond.status_code == 200:
         uid = get_people_id(respond.content)
         return uid
     else:
         logger.error(u'抓取’%s‘用户的id失败' % path)
示例#5
0
    def GetObject(id, **kwargs):
        try:
            config_path = os.path.join(GloalConfig().config, 'config.xml')
            context = ApplicationContext(XMLConfig(config_path))
            obj = context.get_object(id)
            logger.info(obj)

            return obj
        except:
            logger.error("", exc_info=1)
            return None
示例#6
0
 def post(self, msg, audience=[]):
     p = {"api": "/statuses/update.json", "_": int(time.time() * 1000)}
     cookie = self.load_cookies()
     url = urljoin(BASE_URL, TOKEN_URL)
     r = self.session.get(url, params=p, cookies=cookie,
                          headers=BASE_HEADER)
     try:
         token = r.json()['token']
     except (IndexError, TypeError, ValueError):
         logger.error("MLGB 出错了!")
         logger.error("\n%s\n", r.text)
         return
     audience = ' @'.join(audience)
     audience = ' @' + audience.strip()
     msg = '%s %s' % (msg, audience)
     logger.info('发送的内容是: %s' % msg)
     msg = msg.encode().decode()
     data = {"status": "<p>%s</p>" % msg, "session_token": token}
     url = urljoin(BASE_URL, POST_URL)
     r = self.session.post(url, data=data, cookies=cookie,
                           headers=BASE_HEADER)
     if r.status_code == 200:
         data = r.json()
         if not data.get('error_code') > -1:
             logger.debug("完事儿了.")
             return
     logger.error("MLGB 又出错了!")
     logger.error("\n%s\n", r.text)
     raise ValueError('发广播出错了')
示例#7
0
    def wrapper(self, *args, **kw):
        who = 'hejianhao'
        logger.info('<==================== {1} Begin call [{0}] ===================='.format(__get_full_class(self), who))
        start_time = time.time()
        try:
            c = func(self, *args, **kw)
        except Exception as err:
            text = '\n'.join(['an error occured ', str(err), traceback.format_exc()])
            logger.error('ATP: 接口发现未知错误 \n {traceback}'.format(traceback=text))

            c = jsonify({"code": "999", "desc": "system error"})
        end_time = time.time()
        d_time = end_time - start_time
        logger.info("==================== End call [{0}], run {1:.3}s ====================>\n"
                    .format(__get_full_class(self), d_time))
        return c
示例#8
0
    def OpenFile(self):
        if not isinstance(self.action, ActionQ):
            message = QMessageBox(title="错误", text="执行错误")
            message.show()
            return

        try:
            fileDialog = QFileDialog(parent=self.mainWindow, caption=self.action.toolTip())

            # v=QFileDialog.FileMode(2)
            # fileDialog.setFileMode(v)

            files = fileDialog.getOpenFileNames(parent=self.mainWindow, caption=self.action.toolTip())

            return files[0]
        except:
            logger.error(self.error, exc_info=1)
示例#9
0
 def get_chat_sequence_id(self, uid):
     url = CHAT_HISTORY_URL % uid
     params = {
         'user_id': self.uid,
         'limit': 30,
         '_': int(time.time() * 1000)
     }
     cookies = self.load_cookies()
     respond = self.session.get(url, headers=CHAT_HEADER, params=params, cookies=cookies)
     if respond.status_code == 200:
         data = respond.json()
         if len(data) > 1:
             return data[-1]['sequenceId']
         else:
             return 96878141
     logger.error('获得聊天id失败')
     logger.error(respond.content)
     return False
示例#10
0
def _send_chat_msg(user_name, password, msg):
    spider = Spider(user_name=user_name, password=password)
    spider.login()
    chat_obj = Chat.get()
    logger.info(u'开始发送聊天信息,从id为%s的开始' % chat_obj.chatting_id)
    people = People.select().where(People.id > chat_obj.chatting_id).limit(2)
    send_count = 0
    for person in people:
        result = spider.chat(person.uid, msg)
        if not result:
            logger.error(u'发送给’%s‘失败' % person.user_name)
            time.sleep(PERCHAT_INTEVAL)
            continue
        send_count += 1
        logger.info(u'第%s条消息,发送给’%s‘成功' % (send_count, person.user_name))
        chat_obj.chatting_id = person.id
        chat_obj.save()
        time.sleep(PERCHAT_INTEVAL)
示例#11
0
 def check_login(self, load_cookie=True):
     if load_cookie:
         cookies = self.load_cookies()
         response = self.session.get(BASE_URL, headers=BASE_HEADER,
                                     cookies=cookies, allow_redirects=False)
     else:
         response = self.session.get(BASE_URL, headers=BASE_HEADER,
                                     allow_redirects=False)
     if response.status_code == 302:
         if self.uid is not None:
             return True
         location = response.headers['Location']
         uid = get_uid_from_url(location)
         if uid:
             self.uid = uid
             return True
         else:
             logger.error(u"从跳转链接解析uid出错了")
     return False
示例#12
0
def run_testcase(case_dict, common_params):
    cmdline = ''
    try:
        if 'pre_call' in case_dict and case_dict['pre_call']:
            cmdline = case_dict['pre_call']
            logger.info('Going to execute PRE call: {} {}'.format(case_dict['casename'], cmdline))
            pmsg = subprocess.check_output(cmdline, stderr=subprocess.STDOUT, shell=True)
            logger.info(pmsg)
        if 'cmdline' not in case_dict or not case_dict['cmdline']:
            logger.error('Error: cmdline can NOT be empty {}'.format(case_dict['casename']))
            return False
        params = {}
        params.update(common_params)
        params.update(case_dict['params'])
        params_file = os.path.join(TMP_PATH, str(re.sub(r"\s+", "", case_dict['casename'])).lower() + ".json")
        with open(params_file, "w") as fp:
            fp.write(json.dumps(params, indent=True, sort_keys=True, ensure_ascii=False))

        cmdline = case_dict['cmdline'] + " " + params_file
        logger.info('Going to execute cmdline: {} {}'.format(case_dict['casename'], cmdline))
        pmsg = subprocess.check_output(cmdline, stderr=subprocess.STDOUT, shell=True)
        logger.info(pmsg)

        if 'post_call' in case_dict and case_dict['post_call']:
            cmdline = case_dict['post_call']
            logger.info('Going to execute POST call: {} {}'.format(case_dict['casename'], cmdline))
            pmsg = subprocess.check_output(cmdline, stderr=subprocess.STDOUT, shell=True)
            logger.info(pmsg)
        return True
    except Exception as e:
        logger.error('get exception: {} {}'.format(case_dict['casename'], cmdline))
        logger.error(traceback.print_exc())
        return False
示例#13
0
    def OpenFile(self):
        global save_path
        save_path = ''
        if not isinstance(self.action, ActionQ):
            message = QMessageBox(title="错误", text="执行错误")
            message.show()
            return

        try:
            #fileDialog = QFileDialog(parent=self.mainWindow, caption=self.action.toolTip())
            # v=QFileDialog.FileMode(2)
            # fileDialog.setFileMode(v)

            #files = fileDialog.getOpenFileNames(parent=self.mainWindow, caption=self.action.toolTip())
            #files = QFileDialog.getOpenFileNames(self.mainWindow, "选取文件", r"/","Binary files(*.nc , *.hdf ,*.GRB, *.grb2);;All Files (*)")
            fileList = list()
            files = QFileDialog.getOpenFileNames(
                self.mainWindow, "选取文件", save_path,
                "Binary files(*.nc , *.hdf ,*.GRB, *.grb2);;All Files (*)")
            save_path = files[0]
            for file in files[0]:
                modelDataType = jt.judge_model_data_type(file)
                if modelDataType == ModelDataType.NETCDF or modelDataType == ModelDataType.HDF:
                    regex_str = ".*?([\u4E00-\u9FA5]+).*?"
                    match_obj = re.findall(regex_str, file)
                    if match_obj:
                        reply = QMessageBox.information(
                            self, '提示', '您的NetCDF或者HDF文件路径中包含中文,继续执行请点击确认!',
                            QMessageBox.Yes | QMessageBox.No)

                        if reply == QMessageBox.Yes:
                            logpath = os.path.join(os.path.abspath('.'), 'log')
                            if not os.path.exists(logpath):
                                os.makedirs(logpath)
                            tmppath = os.path.join(logpath, 'temp')
                            if not os.path.exists(tmppath):
                                os.makedirs(tmppath)
                            #ncfile = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
                            ncfile = datetime.datetime.now().strftime(
                                '%Y%m%d%H')
                            tmpdir = os.path.join(tmppath, ncfile)
                            if not os.path.exists(tmpdir):
                                os.makedirs(tmpdir)
                            shutil.copy(file, tmpdir)
                            (filepath, tempfilename) = os.path.split(file)
                            file = os.path.join(tmpdir, tempfilename)
                            fileList.append(file)

                        else:
                            pass
                    else:
                        fileList.append(file)
                else:
                    fileList.append(file)

            return fileList
            #return files[0]
        except Exception as arg:
            logger.error(str(arg), exc_info=1)
            print(arg)
            QMessageBox.warning(self, '警告', '打开文件异常,请检查文件!', QMessageBox.Yes,
                                QMessageBox.No)
示例#14
0
                    check_price = round(random.uniform(sell_min, buy_max),
                                        file_config.price_point)
                    if check_price < file_config.confirm_min or check_price > file_config.confirm_max:
                        logger.warning(
                            'The current price {} exceeds the threshold, please check the configuration.'
                            .format(check_price))
                        continue
                    res_sell = order_sell(client, key_ticker, sell_min,
                                          buy_max)
                    res_buy = order_buy(client, key_ticker, sell_min, buy_max)
                if res_buy is False:
                    s_buy = key_ticker.split(file_config.market_separator)[1]
                    logger.warning(
                        'Insufficient account balance : {}'.format(s_buy))
                else:
                    logger.info(json.dumps(res_buy))
                if res_sell is False:
                    s_sell = key_ticker.split(file_config.market_separator)[0]
                    logger.warning(
                        'Insufficient account balance : {}'.format(s_sell))
                else:
                    logger.info(json.dumps(res_sell))
        except Exception as err:
            logger.error(err)

        time.sleep(file_config.sleep_time)
        counter += 1

        if file_config.count and file_config.count <= counter:
            break