X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=google_assistant.py;h=0af4fa9271df3bf2e6de6f3571cfa6c2eb6d1f23;hb=a4bf4d05230474ad14243d67ac7f8c938f670e58;hp=75ca6432cf76b9f84506aa549855e5cec25e1844;hpb=36fea7f15ed17150691b5b3ead75450e575229ef;p=python_utils.git diff --git a/google_assistant.py b/google_assistant.py index 75ca643..0af4fa9 100644 --- a/google_assistant.py +++ b/google_assistant.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import logging -from typing import NamedTuple import sys +from typing import NamedTuple, Optional import warnings import requests @@ -36,7 +36,7 @@ class GoogleResponse(NamedTuple): success: bool response: str audio_url: str - audio_transcription: str + audio_transcription: Optional[str] # None if not available. def __repr__(self): return f""" @@ -67,7 +67,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse: success = False response = "" audio = "" - audio_transcription = "" + audio_transcription: Optional[str] = "" if r.status_code == 200: j = r.json() success = bool(j["success"]) @@ -105,9 +105,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse: audio_transcription=audio_transcription, ) else: - message = ( - f'HTTP request to {url} with {payload} failed; code {r.status_code}' - ) + message = f'HTTP request to {url} with {payload} failed; code {r.status_code}' logger.error(message) return GoogleResponse( success=False,