ServerDowntimeNotifier/WebsitePingService.py

23 lines
414 B
Python

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
"""
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