Exemplo n.º 1
0
    def ask_question(self, bot, clientid: str, question: str):
        try:
            # TODO possibly move this into license.keys
            login = self._config.parameter('login')

            payload = {'input': question, 'login': login}

            response = RequestsAPI.get(PannousService.default_url, params=payload)
            json_data = response.json()

            if 'output' not in json_data:
                raise Exception("'output' section missing from pannous json_data")

            if len(json_data["output"]) == 0:
                raise Exception("'output' section has no elements in pannous json_data")

            if 'actions' not in json_data["output"][0]:
                raise Exception("'actions' section in output[0] in pannous json_data")

            if 'say' not in json_data["output"][0]['actions']:
                raise Exception("'say' section missing from output[0]['actions'] in pannous json_data")

            if 'text' not in json_data["output"][0]['actions']['say']:
                raise Exception("text' section missing from output[0]['actions']['say'] in pannous json_data")

            return json_data["output"][0]['actions']['say']['text']

        except Exception as excep:
            logging.error(str(excep))
            return ""
Exemplo n.º 2
0
    def ask_question(self, bot, clientid: str, question: str):
        try:
            login = self._config.parameter('login')

            payload = {'input': question, 'login': login}

            response = RequestsAPI.get(PannousService.default_url, params=payload)
            json_data = response.json()

            if 'output' not in json_data:
                raise Exception("'output' section missing from pannous json_data")

            if len(json_data["output"]) == 0:
                raise Exception("'output' section has no elements in pannous json_data")

            if 'actions' not in json_data["output"][0]:
                raise Exception("'actions' section in output[0] in pannous json_data")

            if 'say' not in json_data["output"][0]['actions']:
                raise Exception("'say' section missing from output[0]['actions'] in pannous json_data")

            if 'text' not in json_data["output"][0]['actions']['say']:
                raise Exception("text' section missing from output[0]['actions']['say'] in pannous json_data")

            return json_data["output"][0]['actions']['say']['text']

        except Exception as excep:
            logging.error(str(excep))
            return ""
Exemplo n.º 3
0
class PannousAPI(object):

    def __init__(self, request_api=None):
        if request_api is None:
            self._requests_api = RequestsAPI()
        else:
            self._requests_api = request_api

    def ask_question(self, url, question, login):
        payload = {'input': question, 'login': login}

        response = self._requests_api.get(url, params=payload)
        if response is None:
            raise Exception("No response from pannous service")

        json_data = response.json()

        if 'output' not in json_data:
            raise Exception("'output' section missing from pannous json_data")

        if json_data["output"] is None or len(json_data["output"]) == 0:
            raise Exception("'output' section has no elements in pannous json_data")

        if 'actions' not in json_data["output"][0]:
            raise Exception("'actions' section in output[0] in pannous json_data")

        if 'say' not in json_data["output"][0]['actions']:
            raise Exception("'say' section missing from output[0]['actions'] in pannous json_data")

        if 'text' not in json_data["output"][0]['actions']['say']:
            raise Exception("'text' section missing from output[0]['actions']['say'] in pannous json_data")

        return json_data["output"][0]['actions']['say']['text']
Exemplo n.º 4
0
    def ask_question(self, url, question, login):
        payload = {'input': question, 'login': login}

        response = RequestsAPI.get(url, params=payload)
        json_data = response.json()

        if 'output' not in json_data:
            raise Exception("'output' section missing from pannous json_data")

        if len(json_data["output"]) == 0:
            raise Exception(
                "'output' section has no elements in pannous json_data")

        if 'actions' not in json_data["output"][0]:
            raise Exception(
                "'actions' section in output[0] in pannous json_data")

        if 'say' not in json_data["output"][0]['actions']:
            raise Exception(
                "'say' section missing from output[0]['actions'] in pannous json_data"
            )

        if 'text' not in json_data["output"][0]['actions']['say']:
            raise Exception(
                "text' section missing from output[0]['actions']['say'] in pannous json_data"
            )

        return json_data["output"][0]['actions']['say']['text']
Exemplo n.º 5
0
	def execute(self, bot, clientid, data):

		joke = RequestsAPI.get('https://api.chucknorris.io/jokes/random', params=data)
		logging.debug ("Chuck Norris joke [%s]"%(joke.json()['value']))

		if joke is None:
			logging.error("ChuckNorrisAPIExtension joke not found!")
			return ""

		return joke.json()['value']
Exemplo n.º 6
0
	def execute(self, bot, clientid, data):

		joke = RequestsAPI.get('https://webknox-jokes.p.mashape.com/jokes/random', params=data)
		logging.debug ("Mashape joke [%s]"%(joke.json()['value']))

		if joke is None:
			logging.error("Mashape joke not found!")
			return ""

		return joke.json()['value']
Exemplo n.º 7
0
    def ask_question(self, url, question, botid):
        payload = {'botid': botid, 'input': question}
        response = RequestsAPI.get(url, params=payload)

        if response is None:
            raise Exception("No response from service")

        tree = ElementTree.fromstring(response.content)

        that = tree.find("that")
        if that is None:
            raise Exception("Invalid response from service, no 'that'")

        return that.text
Exemplo n.º 8
0
    def ask_question(self, bot, clientid: str, question: str):
        try:
            botid = self._config.parameter('botid')

            payload = {'botid': botid, 'input': question}
            response = RequestsAPI.get(PandoraService.default_url, params=payload)

            if response is None:
                raise Exception("No response from service")

            tree = ElementTree.fromstring(response.content)

            that = tree.find("that")
            if that is None:
                raise Exception("Invalid response from service, no 'that'")

            return that.text

        except Exception as excep:
            logging.error(str(excep))
            return ""
Exemplo n.º 9
0
    def ask_question(self, bot, clientid: str, question: str):
        try:
            botid = self._config.parameter('botid')

            payload = {'botid': botid, 'input': question}
            response = RequestsAPI.get(PandoraService.default_url, params=payload)

            if response is None:
                raise Exception("No response from service")

            tree = ElementTree.fromstring(response.content)

            that = tree.find("that")
            if that is None:
                raise Exception("Invalid response from service, no 'that'")

            return that.text

        except Exception as excep:
            logging.error(str(excep))
            return ""
Exemplo n.º 10
0
class PandoraAPI(object):
    def __init__(self, request_api=None):
        if request_api is None:
            self._requests_api = RequestsAPI()
        else:
            self._requests_api = request_api

    def ask_question(self, url, question, botid):
        payload = {'botid': botid, 'input': question}
        response = self._requests_api.get(url, params=payload)

        if response is None:
            raise Exception("No response from pandora service")

        tree = ElementTree.fromstring(response.content)

        that = tree.find("that")
        if that is None:
            raise Exception(
                "Invalid response from pandora service, no <that> element in xml"
            )

        return that.text
Exemplo n.º 11
0
 def __init__(self, request_api=None):
     if request_api is None:
         self._requests_api = RequestsAPI()
     else:
         self._requests_api = request_api