def handle(text, mic, profile, iot_client=None, chatbot=None): """ 处理 :param text: :param mic: :param profile: :param iot_client: :return: """ plugin_output(text, mic, '我是基于阿里云创建的私人智能语音助理,KIM。')
def handle(text, mic, profile, iot_client=None, chatbot=None): """ 插件入口函数 :param text: :param mic: :param profile: :param iot_client: :param chatbot: :return: """ robot_says = "我的I P地址是 " + __get_host_ip() plugin_output(text, mic, robot_says)
def handle(text, mic, profile, iot_client=None,chatbot=None): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ text_str = ''.join(text) robot_says = text_str.replace('echo', '').replace('传话', '').replace('重复一下', '') plugin_output(text, mic, robot_says)
def handle(text, mic, profile, iot_client=None, chatbot=None): mic.say('正在查询天气...') fc_client = FcClient.get_instance() tree = ET.parse(APP_PATH + '/src/plugins/resources/weather-moji-citys.xml') # 载入数据 xml_root = tree.getroot() #获取根节点 elements = xml_root.findall('./city[@name="' + city + '"]') try: city_id = elements[0].get('id') except: mic.say('没有找到你设定的城市,请修改profile配置文件') finally: if city_id is None: mic.say('没有找到你设定的城市,请修改profile配置文件') data = { 'host': 'http://freecityid.market.alicloudapi.com', 'path': '/whapi/json/alicityweather/briefforecast3days', 'method': 'POST', 'appcode': ali_appcode, 'payload': { 'cityId': city_id }, 'bodys': {}, 'querys': '' } return_text = '' result_raw = json.loads( fc_client.call_function('aliyun_apimarket', payload=data).data.decode('utf8')) if result_raw['msg'] == 'success': return_text += myname + '为您播报,' + result_raw['data']['city'][ 'name'] + '天气预报,' if is_all_word_segment_in_text(['明天', '明日'], text): forecast = result_raw['data']['forecast'][1] day = '明天' elif is_all_word_segment_in_text(['后天', '明日'], text): forecast = result_raw['data']['forecast'][2] day = '后天' else: forecast = result_raw['data']['forecast'][0] day = '今天' forecast_output = return_text + day + forecast['conditionDay']+',白天气温,'+forecast['tempDay'].replace('-', '零下')+\ '摄氏度,夜间气温,'+forecast['tempNight'].replace('-', '零下')+\ '摄氏度,'+forecast['windDirNight']+forecast['windLevelDay'].replace('-', '到')+'级' plugin_output(text, mic, forecast_output) else: mic.say('天气获取失败')
def handle(text, mic, profile, iot_client=None,chatbot=None): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) wxBot -- wechat robot """ tz = pytz.timezone(profile.timezone) now = dt.datetime.now(tz=tz) if is_all_word_segment_in_text(['时间', '几点'], text): plugin_output(text, mic, "现在时间,%s " % now.strftime("%p%I时%M分").replace('AM', '上午').replace('PM', '下午')) else: plugin_output(text, mic, "今天是," + now.strftime("%Y年%m月%d日") + ',星期'+week_map[int(now.strftime('%w'))])
def handle(text, mic, profile, iot_client=None, chatbot=None): """ 处理 :param text: :param mic: :param profile: :param iot_client: :return: """ mic.say('好的,请稍等') fc_client = FcClient.get_instance() data = { 'host': 'http://ali-joke.showapi.com', 'path': '/textJoke', 'method': 'GET', 'appcode': ali_appcode, 'payload': { 'maxResult': '50', 'page': '1', 'time': '' }, 'bodys': {}, 'querys': '' } joke_random = random.randint(0, 9000) data['payload']['page'] = math.floor(joke_random / 50) joke_id_in_page = joke_random % 50 result_raw = json.loads( fc_client.call_function('aliyun_apimarket', payload=data).data.decode('utf8')) logger.info(result_raw) if result_raw['showapi_res_code'] == 0: joke_content = result_raw['showapi_res_body']['contentlist'][ joke_id_in_page] robot_says = joke_content['text'].replace('br', ' ').replace( '<', '').replace('>', '') plugin_output(text, mic, robot_says) else: robot_says = '我好像出了什么问题,需要治疗一下。调试信息:' + json.dumps(result_raw) plugin_output(text, mic, robot_says)