current_session_id = intent_message.session_id hermes.publish_end_session(current_session_id, res.decode("utf-8")) if __name__ == "__main__": config = read_configuration_file("config.ini") if config.get("secret").get("api_key") is None: print "No API key in config.ini, you must setup an OpenWeatherMap API key for this skill to work" elif len(config.get("secret").get("api_key")) == 0: print "No API key in config.ini, you must setup an OpenWeatherMap API key for this skill to work" skill_locale = config.get("global", { "locale": "en_US" }).get("locale", u"en_US") skill = SnipsOWM(config["secret"]["api_key"], config["secret"]["default_location"], locale=skill_locale.decode('ascii')) with Hermes(MQTT_ADDR.encode("ascii")) as h: h.skill = skill h.subscribe_intent("Martin1887:buscarPronosticoDeObjeto", searchWeatherForecastItem) \ .subscribe_intent("Martin1887:buscarPronosticoDeTemperatura", searchWeatherForecastTemperature) \ .subscribe_intent("Martin1887:buscarPronosticoDeCondicion", searchWeatherForecastCondition) \ .subscribe_intent("Martin1887:buscarPronostico", searchWeatherForecast) \ .loop_forever()
def start_blocking(self): with Hermes(MQTT_ADDR) as h: h.subscribe_intents(self.master_intent_callback).start()
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import ConfigParser from hermes_python.hermes import Hermes from hermes_python.ontology import * import io CONFIGURATION_ENCODING_FORMAT = "utf-8" # CONFIG_INI = "config.ini" def subscribe_intent_callback(hermes, intentMessage): intentname = intentMessage.intent.intent_name if intentname == "bertron:Fuchs": result_sentence = "Whoa papapapapapapapau" hermes.publish_end_session(intentMessage.session_id, result_sentence) elif intentname == "bertron:Crystal": result_sentence = "Herzlichen Glückwunsch, ich bin doch nicht schwanger. Sie haben das sett app abgeschlossen" hermes.publish_end_session(intentMessage.session_id, result_sentence) elif intentname == "bertron:Schoenste": result_sentence = "Frau Königin Ihr seid die Schönste hier aber Schneewittchen hinter den sieben Bergen bei den sieben Zwergen ist noch tausend Mal schöner als Ihr" hermes.publish_end_session(intentMessage.session_id, result_sentence) if __name__ == "__main__": with Hermes("localhost:1883") as h: h.subscribe_intents(subscribe_intent_callback).start()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from hermes_python.hermes import Hermes from hermes_python.ffi.utils import MqttOptions from hermes_python.ontology import * import mossrock as mr CONFIG_INI = "config.ini" def subscribe_intent_callback(hermes, intentMessage): conf = mr.read_configuration_file(CONFIG_INI) action_wrapper(hermes, intentMessage, conf) def action_wrapper(hermes, intentMessage, conf): resp_msg = mr.send_scene_command(mr.get_scene_name(intentMessage)) hermes.publish_end_session(intentMessage.session_id, resp_msg) if __name__ == "__main__": mqtt_opts = MqttOptions() with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent("psiniemi:enable_scene", subscribe_intent_callback) \ .start()
ph = pred_humedad(hoy) pl = pred_lluvia(hoy) pn = pred_nieve(hoy) pv = pred_viento(hoy) sentence = 'La predicción de ' + clima + ' en ' + municipio + ' para ' + fr_fecha + ' según la Agencia Estatal de Meteorología es la siguiente: ' if clima == 'cielo': sentence += pc if clima == 'temperatura': sentence += pt if clima == 'humedad': sentence += ph if clima == 'lluvia': sentence += pl + pn if clima == 'nieve': sentence += pn if clima == 'viento': sentence += pv if clima == 'tiempo': sentence += pc + pt + pl + pn + ph + pv else: return hermes.publish_end_session(intentMessage.session_id, sentence) with Hermes(MQTT_ADDR) as h: h.subscribe_intents(intent_received).start()
result_sentence = shoppinglist.show() hermes.publish_end_session(intent_message.session_id, result_sentence) elif intentname == add_prefix("sendShoppingList"): result_sentence = shoppinglist.send() hermes.publish_end_session(intent_message.session_id, result_sentence) def intent_not_recognized_callback(hermes, intent_message): configure_message = DialogueConfiguration().disable_intent(add_prefix("confirmShoppingList")) hermes.configure_dialogue(configure_message) shoppinglist.wanted_intents = [] hermes.publish_end_session({'sessionId': intent_message.session_id, 'text': "Die Einkaufsliste wurde nicht gelöscht."}) if __name__ == "__main__": snips_config = toml.load('/etc/snips.toml') if 'mqtt' in snips_config['snips-common'].keys(): MQTT_BROKER_ADDRESS = snips_config['snips-common']['mqtt'] if 'mqtt_username' in snips_config['snips-common'].keys(): MQTT_USERNAME = snips_config['snips-common']['mqtt_username'] if 'mqtt_password' in snips_config['snips-common'].keys(): MQTT_PASSWORD = snips_config['snips-common']['mqtt_password'] config = read_configuration_file("config.ini") shoppinglist = ShoppingList(config) with Hermes(MQTT_BROKER_ADDRESS) as h: h.subscribe_intents(intent_callback) h.start()