def get_yigeai(text, userid): """ 『一个AI』自动回复 (http://www.yige.ai/) 接口说明:http://docs.yige.ai/Query%E6%8E%A5%E5%8F%A3.html :param text:str, 需要发送的话 :userid:str,机器唯一标识 :return:str """ try: # config.init() info = config.get('auto_reply_info')['yigeai_conf'] token = info['client_token'] if not token: print('一个「AI」token 为空,请求出错') return None session_id = md5_encode(userid if userid else '250') # print('发出的消息:{}'.format(text)) data = {'token': token, 'query': text, 'session_id': session_id} resp = requests.post('http://www.yige.ai/v1/query', data=data) if resp.status_code == 200 and is_json(resp): # print(resp.text) re_data = resp.json() code = re_data['status']['code'] # 错误码返回有时是数字,有点是str。一起做处理 if code and str(code) not in TULING_ERROR_CODE_LIST: return_text = re_data['answer'] return return_text error_text = re_data['status']['error_type'] print('『一个AI』机器人错误信息:{}'.format(error_text)) return None print('『一个AI』机器人获取数据失败') except Exception as e: print(e) print('『一个AI』机器人获取数据失败')
def get_tuling123(text, userId): """ 接口地址:(https://www.kancloud.cn/turing/www-tuling123-com/718227) 获取图灵机器人对话 :param text: 发送的话 :param userId: 用户唯一标识(最好用微信好友uuid) :return: 对白 """ try: # config.init() info = config.get('auto_reply_info')['turing_conf'] apiKey = info['apiKey'] if not apiKey: print('图灵机器人 apikey 为空,请求出错') return None userId = md5_encode(userId if userId else '250') content = { 'perception': { 'inputText': { 'text': text } }, 'userInfo': { 'apiKey': apiKey, 'userId': userId } } # print('发出消息:{}'.format(text)) resp = requests.post(URL, json=content) if resp.status_code == 200 and is_json(resp): # print(resp.text) re_data = resp.json() if re_data['intent']['code'] not in TULING_ERROR_CODE_LIST: return_text = re_data['results'][0]['values']['text'] return return_text error_text = re_data['results'][0]['values']['text'] print('图灵机器人错误信息:{}'.format(error_text)) return None print('图灵机器人获取数据失败') except Exception as exception: print(str(exception)) print('图灵机器人获取数据失败')
def get_acib_info(): """ 从词霸中获取每日一句,带英文。 :return:str ,返回每日一句(双语) """ print('获取格言信息(双语)...') try: resp = requests.get('http://open.iciba.com/dsapi') if resp.status_code == 200 and is_json(resp): content_dict = resp.json() content = content_dict.get('content') note = content_dict.get('note') return '{}{}'.format(content, note) print('没有获取到格言数据。') except requests.exceptions.RequestException as exception: print(exception)
def get_acib_info(): """ 从词霸中获取每日一句,带英文。 :return:str ,返回每日一句(双语) """ print('获取格言信息(双语)...') try: resp = requests.get('https://api.ooopn.com/ciba/api.php?type=json') if resp.status_code == 200 and is_json(resp): content_dict = resp.json() content = content_dict.get('ciba') note = content_dict.get('ciba-en') return '{}{}'.format(content, note) print('没有获取到格言数据。') except requests.exceptions.RequestException as exception: print(exception) return None