Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
Fixes after some API changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 9, 2019
1 parent 5f78ed7 commit a2808e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
14 changes: 8 additions & 6 deletions src/botadi/mokadi/cognitive_services_helper.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/botadi/mokadi/mokadi_action_emotion.py
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit a2808e5

Please sign in to comment.