def language(self, _text): self.logger.debug('需要判断语言的单词为:%s' % _text) _src = None fetchone = self.mysql_api.query_one( 'select `type` from str_language where str_key = %s;', _text) if fetchone is not None: _src = fetchone[0] self.logger.debug('从数据库中查询到了单词的语言') else: self.logger.debug('从数据库中没有查询到语言,开始调用接口查询') if _src is None: salt = str(random.randint(0, 999999)) sign = hashlib.md5((self.app_id + _text + salt + self.app_secret).encode('utf8')).hexdigest() http_get = util.HttpGet( 'https://fanyi-api.baidu.com/api/trans/vip/language') http_get.add_param('q', _text) http_get.add_param('appid', self.app_id) http_get.add_param('salt', salt) http_get.add_param('sign', sign) http_get.execute() json = http_get.get_json() if json['error_code'] is 0: self.logger.debug('查询到单词的语言,开始入库') _src = json['data']['src'] if _src != 'zh': _src = 'en' self.mysql_api.execute( 'insert into str_language (str_key, type) VALUE (%s,%s);', (_text, _src)) else: if re.findall('\u4e00-\u9fa5', _text).__len__() > 0: _src = 'zh' else: _src = 'en' self.mysql_api.execute( 'insert into str_language (str_key, type) VALUE (%s,%s);', (_text, _src)) return _src return _src
def customer_trans(self, _text, _to): self.logger.debug('开始翻译单词,单词:%s,目标语言:%s' % (_text, _to)) _dst = None fetchone = self.mysql_api.query_one( 'select `value` from str_trans where str_key = %s and language = %s;', (_text, _to)) if fetchone is not None: self.logger.debug('数据库中查询到了结果,直接返回') _dst = fetchone[0] else: self.logger.debug('数据库中没有查询到结果,开始调接口查询') if _dst is None: salt = str(random.randint(0, 999999)) sign = hashlib.md5((self.app_id + _text + salt + self.app_secret).encode('utf8')).hexdigest() _src = self.language(_text) self.logger.debug('来源语言为:%s' % _src) http_get = util.HttpGet( 'https://fanyi-api.baidu.com/api/trans/vip/translate') http_get.add_param('q', _text) http_get.add_param('appid', self.app_id) http_get.add_param('salt', salt) http_get.add_param('sign', sign) http_get.add_param('from', _src) http_get.add_param('to', _to) http_get.execute() json = http_get.get_json() if 'error_msg' not in json: self.logger.debug('翻译单词成功,开始入库') _dst = json['trans_result'][0]['dst'] self.mysql_api.execute( 'insert into str_trans (str_key, language, value) VALUE (%s,%s,%s);', (_text, _to, _dst)) else: raise TransError(json['error_msg']) return _dst
{'ip': '192.168.3.165', 'port': '2145', 'domain': 'oms-api'}, {'ip': '192.168.3.165', 'port': '2146', 'domain': 'oms-dataex'}, {'ip': '192.168.3.165', 'port': '2147', 'domain': 'oms-task'}, {'ip': '192.168.3.165', 'port': '2148', 'domain': 'oms-web'}, {'ip': '192.168.3.165', 'port': '2149', 'domain': 'opay-web'}, {'ip': '192.168.3.165', 'port': '2150', 'domain': 'opms-web'}, {'ip': '192.168.3.165', 'port': '2151', 'domain': 'ouser-web'}, # {'ip': '192.168.3.165', 'port': '2152', 'domain': 'search'}, {'ip': '192.168.3.165', 'port': '2153', 'domain': 'social-back-web'}, {'ip': '192.168.3.165', 'port': '2154', 'domain': 'social-web'}, {'ip': '192.168.3.165', 'port': '2156', 'domain': 'live-web'}, {'ip': '192.168.3.165', 'port': '2133', 'domain': 'back-product-service'} ] for i in pool_map: testBusinessException = util.HttpGet( 'http://' + i['ip'] + ':' + i['port'] + '/' + i['domain'] + '/testException/testBusinessException') testBusinessException.execute() print(i['domain']) text = testBusinessException.get_text() print(' rest') if not text.__contains__('999999'): print(' ' + text) soa = util.HttpGet( 'http://' + i['ip'] + ':' + i['port'] + '/' + i[ 'domain'] + '/cloud/pathInfo') soa.execute() if soa.get_text().startswith('['): testBusinessException = util.HttpGet( 'http://' + i['ip'] + ':' + i['port'] + '/' + i[ 'domain'] + '/cloud/testExceptionService/testExceptionControllerAdvice') try:
def __init_config__(self): get = util.HttpGet(self.jenkins_api.jenkins_path + '/job/' + self.job_name + '/config.xml') get.execute() self.config = ET.fromstring(get.get_text())
def __init_job__(self): get = util.HttpGet(self.jenkins_api.jenkins_path + '/job/' + self.job_name + '/api/json?pretty=true') get.execute() self.job = get.get_json()
def __init_view__(self): get = util.HttpGet(self.jenkins_api.jenkins_path + '/view/' + self.view_name + '/api/json?pretty=true') get.execute() self.view = get.get_json()
def __init_root__(self): get = util.HttpGet(self.jenkins_api.get_jenkins_path() + 'api/json?pretty=true') get.execute() self.root = get.get_json()