ServerDowntimeNotifier/WebsitePingService.py

17 lines
335 B
Python
Raw Normal View History

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
"""
try:
res = requests.get(url)
except:
return -1
if res:
return res.status_code
else:
return -1