2021-03-10 21:07:52 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
def ping(url: str) -> int:
|
|
|
|
"""
|
|
|
|
Makes a GET request to the given website and returns the HTTP status code or -1 in case of failure
|
|
|
|
:param url: The URL of the website to ping
|
|
|
|
:return: The HTTP status code
|
|
|
|
"""
|
|
|
|
|
2021-03-20 18:37:17 +00:00
|
|
|
NUMBER_OF_ATTEMPTS = 5
|
|
|
|
|
|
|
|
for iteration in range(NUMBER_OF_ATTEMPTS):
|
|
|
|
res = None
|
|
|
|
try:
|
|
|
|
res = requests.get(url)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if res:
|
|
|
|
return res.status_code
|
|
|
|
|
|
|
|
return -1
|