File size: 2,974 Bytes
8d7ec5c
 
 
 
 
f3098a6
8d7ec5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests

def getStatus(URL):
    try:
        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'}
        webResponse = requests.get(URL, headers=headers, verify=False, timeout=5)
        webCode = str(webResponse.status_code)
        code, status, webStatus, moreDetails = statusCodes(webCode)
        return code, status, webStatus, moreDetails
    except requests.ConnectionError:
        error = f"Failed to connect to {URL}"
        return error, error, error, error
    except requests.Timeout:
        error = f"Request to {URL} timed out"
        return error, error, error, error
    except requests.RequestException as e:
        error = f"An error occurred: {e}"
        return error, error, error, error
    
def statusCodes(code):
        try:
            if code.startswith("2"):
                status = f"Website is Online and Accessible"
                webStatus = f"The website is currently functioning optimally and delivering content successfully"
                moreDetails = f"https://httpstatuses.io/{code}"
                return code, status, webStatus, moreDetails
            elif code.startswith("3"):
                status = "Website Online, but Redirecting"
                webStatus = f"The website is employing a redirection mechanism to direct users to a different URL (Redirection code: {code})."
                moreDetails = f"https://httpstatuses.io/{code}"
                return code, status, webStatus, moreDetails
            elif code.startswith("4"):
                status = "Website Online, but Inaccessible. Client-side Error or Unauthorization Error or Authentication Error"
                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. "
                moreDetails = f"https://httpstatuses.io/{code}"
                return code, status, webStatus, moreDetails
            elif code.startswith("5"):
                status = "Website Offline. Server-side Error"
                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."
                moreDetails = f"https://httpstatuses.io/{code}"
                return code, status, webStatus, moreDetails
            else:
                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"
        except KeyError:
            return "Unable to fetch website status", "Unable to fetch website status", "Unable to fetch website status", "Unable to fetch website status"