File size: 2,413 Bytes
a6b8177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4c96fd
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
import json

def run(code):
    code, webstatus, status, morestatus = getStatus(code)
    return code, webstatus, status, morestatus

def getStatus(code):
    with open('/home/user/app/status.json', 'r') as file:
        data = json.load(file)
        try:
            if code.startswith("2"):
                status = data['WebStatus']['Online']['SuccessfulConnection'][code]
                code = code
                webstatus = "Online"
                status = status
                morestatus = f"The website is currently functioning optimally and delivering content successfully."
                return code, webstatus, status, morestatus
            elif code.startswith("3"):
                status = data['WebStatus']['Online']['Redirection'][code]
                code = code
                webstatus = "Online"
                status = status
                morestatus = f"The website is employing a redirection mechanism to direct users to a different URL (Redirection code: {code})."
                return code, webstatus, status, morestatus
            elif code.startswith("4"):
                status = data['WebStatus']['Offline']['ClientError'][code]
                code = code
                webstatus = "Offline. Client-side Error or Unauthorization Error or Authentication Error."
                status = status
                morestatus = f"Website is offline due to a client-side error (Client Error code: {code}). This could be caused by an invalid request or issue with your browser."
                return code, webstatus, status, morestatus
            elif code.startswith("5"):
                status = data['WebStatus']['Offline']['ServerError'][code]
                code = code
                webstatus = "Offline"
                status = status
                morestatus = f"Website is offline due to a server-side error (Server Error code: {code}). This indicates an issue with the website itself or its infrastructure."
                return code, webstatus, status, morestatus
            else:
                return "Invalid status code. Please contact us for assistance.", "Invalid status code. Please contact us for assistance.", "Invalid status code. Please contact us for assistance.", "Invalid status code. Please contact us for assistance."
        except KeyError:
            return "abc.", "def.", "ghi.", "jkl."

if __name__ == "__main__":
    run()