Migrate OpenWeaterMap to new library (support API 3.0) (#116870)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Evgeny 2024-05-24 09:51:10 +02:00 committed by GitHub
parent 5bca9d142c
commit 24d31924a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 580 additions and 523 deletions

View file

@ -0,0 +1,20 @@
"""Util functions for OpenWeatherMap."""
from pyopenweathermap import OWMClient, RequestError
async def validate_api_key(api_key, mode):
"""Validate API key."""
api_key_valid = None
errors, description_placeholders = {}, {}
try:
owm_client = OWMClient(api_key, mode)
api_key_valid = await owm_client.validate_key()
except RequestError as error:
errors["base"] = "cannot_connect"
description_placeholders["error"] = str(error)
if api_key_valid is False:
errors["base"] = "invalid_api_key"
return errors, description_placeholders