mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-16 13:14:20 +02:00
polybar-weather: add a timeout to requests
This commit is contained in:
parent
4d350646c0
commit
5da755a496
1 changed files with 3 additions and 1 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue