raannakasturi commited on
Commit
8d7ec5c
·
verified ·
1 Parent(s): 89c0a60

Update getStatus.py

Browse files
Files changed (1) hide show
  1. getStatus.py +45 -45
getStatus.py CHANGED
@@ -1,45 +1,45 @@
1
- import requests
2
-
3
- def getStatus(URL):
4
- try:
5
- headers = {'User-Agent': 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +https://www.google.com/bot.html) Safari/537.36'}
6
- webResponse = requests.get(URL, headers=headers, timeout=5)
7
- webCode = str(webResponse.status_code)
8
- code, status, webStatus, moreDetails = statusCodes(webCode)
9
- return code, status, webStatus, moreDetails
10
- except requests.ConnectionError:
11
- error = f"Failed to connect to {URL}"
12
- return error, error, error, error
13
- except requests.Timeout:
14
- error = f"Request to {URL} timed out"
15
- return error, error, error, error
16
- except requests.RequestException as e:
17
- error = f"An error occurred: {e}"
18
- return error, error, error, error
19
-
20
- def statusCodes(code):
21
- try:
22
- if code.startswith("2"):
23
- status = f"Website is Online and Accessible"
24
- webStatus = f"The website is currently functioning optimally and delivering content successfully"
25
- moreDetails = f"https://httpstatuses.io/{code}"
26
- return code, status, webStatus, moreDetails
27
- elif code.startswith("3"):
28
- status = "Website Online, but Redirecting"
29
- webStatus = f"The website is employing a redirection mechanism to direct users to a different URL (Redirection code: {code})."
30
- moreDetails = f"https://httpstatuses.io/{code}"
31
- return code, status, webStatus, moreDetails
32
- elif code.startswith("4"):
33
- status = "Website Online, but Inaccessible. Client-side Error or Unauthorization Error or Authentication Error"
34
- webStatus = f"Website is inaccessible due to a client-side error (Client Error code: {code}). This could be caused by an invalid request or the website is protected by captcha or against bots. "
35
- moreDetails = f"https://httpstatuses.io/{code}"
36
- return code, status, webStatus, moreDetails
37
- elif code.startswith("5"):
38
- status = "Website Offline. Server-side Error"
39
- webStatus = f"Website is offline due to a server-side error (Server Error code: {code}). This could be caused by the issues with the website itself or its infrastructure."
40
- moreDetails = f"https://httpstatuses.io/{code}"
41
- return code, status, webStatus, moreDetails
42
- else:
43
- return "Unable to fetch website status. Please contact us for assistance", "Unable to fetch website status. Please contact us for assistance", "Unable to fetch website status. Please contact us for assistance", "Unable to fetch website status. Please contact us for assistance"
44
- except KeyError:
45
- return "Unable to fetch website status", "Unable to fetch website status", "Unable to fetch website status", "Unable to fetch website status"
 
1
+ import requests
2
+
3
+ def getStatus(URL):
4
+ try:
5
+ headers = {'User-Agent': 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +https://www.google.com/bot.html) Safari/537.36'}
6
+ webResponse = requests.get(URL, headers=headers)
7
+ webCode = str(webResponse.status_code)
8
+ code, status, webStatus, moreDetails = statusCodes(webCode)
9
+ return code, status, webStatus, moreDetails
10
+ except requests.ConnectionError:
11
+ error = f"Failed to connect to {URL}"
12
+ return error, error, error, error
13
+ except requests.Timeout:
14
+ error = f"Request to {URL} timed out"
15
+ return error, error, error, error
16
+ except requests.RequestException as e:
17
+ error = f"An error occurred: {e}"
18
+ return error, error, error, error
19
+
20
+ def statusCodes(code):
21
+ try:
22
+ if code.startswith("2"):
23
+ status = f"Website is Online and Accessible"
24
+ webStatus = f"The website is currently functioning optimally and delivering content successfully"
25
+ moreDetails = f"https://httpstatuses.io/{code}"
26
+ return code, status, webStatus, moreDetails
27
+ elif code.startswith("3"):
28
+ status = "Website Online, but Redirecting"
29
+ webStatus = f"The website is employing a redirection mechanism to direct users to a different URL (Redirection code: {code})."
30
+ moreDetails = f"https://httpstatuses.io/{code}"
31
+ return code, status, webStatus, moreDetails
32
+ elif code.startswith("4"):
33
+ status = "Website Online, but Inaccessible. Client-side Error or Unauthorization Error or Authentication Error"
34
+ webStatus = f"Website is inaccessible due to a client-side error (Client Error code: {code}). This could be caused by an invalid request or the website is protected by captcha or against bots. "
35
+ moreDetails = f"https://httpstatuses.io/{code}"
36
+ return code, status, webStatus, moreDetails
37
+ elif code.startswith("5"):
38
+ status = "Website Offline. Server-side Error"
39
+ webStatus = f"Website is offline due to a server-side error (Server Error code: {code}). This could be caused by the issues with the website itself or its infrastructure."
40
+ moreDetails = f"https://httpstatuses.io/{code}"
41
+ return code, status, webStatus, moreDetails
42
+ else:
43
+ return "Unable to fetch website status. Please contact us for assistance", "Unable to fetch website status. Please contact us for assistance", "Unable to fetch website status. Please contact us for assistance", "Unable to fetch website status. Please contact us for assistance"
44
+ except KeyError:
45
+ return "Unable to fetch website status", "Unable to fetch website status", "Unable to fetch website status", "Unable to fetch website status"