refuse setting location to timezones we can't understand

This commit is contained in:
jesopo 2020-11-09 23:32:44 +00:00
parent 74da824e53
commit 8cc47a9321

View file

@ -2,6 +2,7 @@
#--require-config opencagedata-api-key
import typing
import pytz
from src import ModuleManager, utils
URL_OPENCAGE = "https://api.opencagedata.com/geocode/v1/json"
@ -19,6 +20,11 @@ class Module(ModuleManager.BaseModule):
if page and page["results"]:
result = page["results"][0]
timezone = result["annotations"]["timezone"]["name"]
try:
pytz.timezone(timezone)
except pytz.exceptions.UnknownTimeZoneError:
return None
lat = result["geometry"]["lat"]
lon = result["geometry"]["lng"]