diff --git a/requirements.txt b/requirements.txt index 42c5552..890a841 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ antlr4-python3-runtime coverage jyquickhelper +git+https://github.com/sdpython/nbconvert.git@fixes pymmails pyquickhelper>=1.8 python-pptx diff --git a/src/botadi/mokadi/cognitive_services_helper.py b/src/botadi/mokadi/cognitive_services_helper.py index 9dbb8d3..bcf9110 100644 --- a/src/botadi/mokadi/cognitive_services_helper.py +++ b/src/botadi/mokadi/cognitive_services_helper.py @@ -13,7 +13,7 @@ def bytes2python(answer): """ - Converts JSON bytes into a dictionary. + Converts :epkg:`JSON` bytes into a dictionary. @param answer bytes @return any type @@ -25,7 +25,7 @@ def bytes2python(answer): def call_api_news(subscription_key, query, market="fr-FR", count=10, offset=0): """ - Retrieve resuls for news. + Retrieves resuls for the news API. @param subscription_key @param query query @@ -112,7 +112,7 @@ def call_api_news(subscription_key, query, market="fr-FR", count=10, offset=0): def call_api_images(subscription_key, query, market="fr-FR", count=10, offset=0): """ - Retrieve resuls for images. + Retrieves resuls for the image API. @param subscription_key @param query query @@ -193,7 +193,7 @@ def call_api_speech_reco(subkey, lang="fr-FR", filename=None, memwav=None, def call_api_emotions(subkey, image_or_bytes): """ - Retrieve resuls for news + Retrieves resuls for the emotions API. @param subkey subscription key @param image_or_bytes image or bytes @@ -205,8 +205,7 @@ def call_api_emotions(subkey, image_or_bytes): 'Ocp-Apim-Subscription-Key': subkey, } - params = urllib.parse.urlencode({ - }) + params = urllib.parse.urlencode({}) if isinstance(image_or_bytes, str): with open(image_or_bytes, "rb") as f: @@ -224,5 +223,8 @@ def call_api_emotions(subkey, image_or_bytes): conn.close() return bytes2python(data) except Exception as e: + import pprint + pprint.pprint(e) + pprint.pprint(e.__dict__) raise CognitiveException("[Errno {0}] {1}".format( getattr(e, 'errno', '-'), getattr(e, 'strerror', '-'))) from e diff --git a/src/botadi/mokadi/mokadi_action_emotion.py b/src/botadi/mokadi/mokadi_action_emotion.py index d254d82..e2f8367 100644 --- a/src/botadi/mokadi/mokadi_action_emotion.py +++ b/src/botadi/mokadi/mokadi_action_emotion.py @@ -64,7 +64,7 @@ def get_picture_name(self): def process_interpreted_message(self, interpretation, message): """ - Process the interpreted message. + Processes the interpreted message. @param interpretation interpretation @param message original message @@ -79,7 +79,7 @@ def process_interpreted_message(self, interpretation, message): done = False res = call_api_emotions(self._subkey, filename) self.fLOG("[MokadiActionEmotion.process_interpreted_message] ", res) - if len(res) == 0: + if len(res) == 0 or res.get('statusCode', 200) == 404: yield MokadiInfo("error", "", "Aucun résultat. Veuillez recommencer.") done = True elif "error" in res: