polybar-weather: add a timeout to requests

This commit is contained in:
Vincent Bernat 2021-12-15 21:19:53 +01:00
parent 4d350646c0
commit 5da755a496

View file

@ -20,6 +20,7 @@ def get_location():
r = requests.get( r = requests.get(
"https://www.maxmind.com/geoip/v2.1/city/me", "https://www.maxmind.com/geoip/v2.1/city/me",
headers={"referer": "https://www.maxmind.com/en/locate-my-ip-address"}, headers={"referer": "https://www.maxmind.com/en/locate-my-ip-address"},
timeout=10,
) )
r.raise_for_status() r.raise_for_status()
data = r.json() data = r.json()
@ -45,6 +46,7 @@ def get_weather(apikey, latitude, longitude):
"units": "metric", "units": "metric",
"exclude": "minutely,hourly", "exclude": "minutely,hourly",
}, },
timeout=10,
) )
r.raise_for_status() r.raise_for_status()
data = r.json() data = r.json()
@ -145,7 +147,7 @@ if __name__ == "__main__":
try: try:
location, city = get_location() location, city = get_location()
break break
except requests.exceptions.ConnectionError: except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
# Wait to be online # Wait to be online
logger.info("not online, waiting") logger.info("not online, waiting")
update_status("", options.output) update_status("", options.output)