From c8a2c0b634f6f6f1a08f28ac5f2a3f98668ea2ea Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Sat, 30 Apr 2022 21:02:46 +0200 Subject: [PATCH] Fix search can't be used two times --- brains/search.yml | 2 +- resources/neurons/search/search.py | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/brains/search.yml b/brains/search.yml index d37488b..8a9be20 100644 --- a/brains/search.yml +++ b/brains/search.yml @@ -6,4 +6,4 @@ message: - "Recherche effectuée" - search: - search: "{{search}}" \ No newline at end of file + search: "{{ search }}" \ No newline at end of file diff --git a/resources/neurons/search/search.py b/resources/neurons/search/search.py index ca8bc32..14f44f7 100644 --- a/resources/neurons/search/search.py +++ b/resources/neurons/search/search.py @@ -1,15 +1,26 @@ -import logging import subprocess from kalliope.core import NeuronModule -from kalliope.core.NeuronModule import MissingParameterException +from kalliope.core.NeuronModule import MissingParameterException, MissingParameterException class Search(NeuronModule): def __init__(self, **kwargs): - super(Search, self).__init__(**kwargs) + NeuronModule.__init__(self, **kwargs) self.query = kwargs.get('search', None) - if self.query is not None: - command = "xdg-open \"https://www.google.fr/search?q="+self.query+"&ie=utf-8&oe=utf-8\" &" + if self._is_parameters_ok(): + command = "xdg-open \"https://www.google.fr/search?q="+self.query+"&ie=utf-8&oe=utf-8\"" p = subprocess.Popen(command, shell=True) + self.say("Youpiiiii") + + def _is_parameters_ok(self): + """ + Check if received parameters are ok to perform operations in the neuron + :return: true if parameters are ok, raise an exception otherwise + .. raises:: MissingParameterException + """ + if self.query is None: + raise MissingParameterException("Query parameter is missing.") + + return True