raannakasturi
commited on
Commit
•
b4c96fd
1
Parent(s):
8fbf53e
Upload 4 files
Browse files- app.py +64 -0
- getStatus.py +45 -0
- requirements.txt +72 -0
- status.json +75 -0
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from getStatus import run # Assuming this module contains the run function
|
4 |
+
|
5 |
+
def getURL(URL):
|
6 |
+
if URL.startswith("http://") or URL.startswith("https://"):
|
7 |
+
websiteUrl = URL
|
8 |
+
else:
|
9 |
+
websiteUrl = "http://" + URL
|
10 |
+
return websiteUrl
|
11 |
+
|
12 |
+
def setHeaders(websiteUrl):
|
13 |
+
try:
|
14 |
+
URL = getURL(websiteUrl)
|
15 |
+
web_response = requests.get(URL, timeout=5)
|
16 |
+
user_agent = web_response.request.headers['User-Agent']
|
17 |
+
headers = {'User-Agent': user_agent}
|
18 |
+
return headers
|
19 |
+
except requests.RequestException as e:
|
20 |
+
print(f"Error fetching headers: {e}")
|
21 |
+
return None
|
22 |
+
|
23 |
+
def websiteStatus(websiteUrl, user_agent_choice):
|
24 |
+
try:
|
25 |
+
URL = getURL(websiteUrl)
|
26 |
+
|
27 |
+
if user_agent_choice == "Your Browser Headers":
|
28 |
+
headers = setHeaders(websiteUrl)
|
29 |
+
else:
|
30 |
+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
|
31 |
+
|
32 |
+
web_response = requests.get(URL, headers=headers)
|
33 |
+
web_status = str(web_response.status_code)
|
34 |
+
code, webstatus, status, morestatus = run(web_status)
|
35 |
+
print(f"Processed Output: {code}, {webstatus}, {status}, {morestatus}") # Debug print
|
36 |
+
return code, webstatus, status, morestatus
|
37 |
+
|
38 |
+
except requests.ConnectionError:
|
39 |
+
error = f"Failed to connect to {websiteUrl}"
|
40 |
+
return error, error, error, error
|
41 |
+
except requests.Timeout:
|
42 |
+
error = f"Request to {websiteUrl} timed out"
|
43 |
+
return error, error, error, error
|
44 |
+
except requests.RequestException as e:
|
45 |
+
error = f"An error occurred: {e}"
|
46 |
+
return error, error, error, error
|
47 |
+
|
48 |
+
# Create a Gradio interface
|
49 |
+
app = gr.Interface(
|
50 |
+
fn=websiteStatus,
|
51 |
+
inputs=[
|
52 |
+
gr.Textbox(label="Enter URL", placeholder="https://google.com", type="text"),
|
53 |
+
gr.Radio(["Your Browser Headers", "Our Server Headers"], label="Select User Agent")
|
54 |
+
],
|
55 |
+
outputs=[
|
56 |
+
gr.Textbox(label="Code", type="text"),
|
57 |
+
gr.Textbox(label="Server/Website Status", type="text"),
|
58 |
+
gr.Textbox(label="Code Status", type="text"),
|
59 |
+
gr.Textbox(label="More Code Status Information", type="text")
|
60 |
+
]
|
61 |
+
)
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
app.launch()
|
getStatus.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
def run(code):
|
4 |
+
code, webstatus, status, morestatus = getStatus(code)
|
5 |
+
return code, webstatus, status, morestatus
|
6 |
+
|
7 |
+
def getStatus(code):
|
8 |
+
with open('./status.json', 'r') as file:
|
9 |
+
data = json.load(file)
|
10 |
+
try:
|
11 |
+
if code.startswith("2"):
|
12 |
+
status = data['WebStatus']['Online']['SuccessfulConnection'][code]
|
13 |
+
code = code
|
14 |
+
webstatus = "Online"
|
15 |
+
status = status
|
16 |
+
morestatus = f"The website is currently functioning optimally and delivering content successfully."
|
17 |
+
return code, webstatus, status, morestatus
|
18 |
+
elif code.startswith("3"):
|
19 |
+
status = data['WebStatus']['Online']['Redirection'][code]
|
20 |
+
code = code
|
21 |
+
webstatus = "Online"
|
22 |
+
status = status
|
23 |
+
morestatus = f"The website is employing a redirection mechanism to direct users to a different URL (Redirection code: {code})."
|
24 |
+
return code, webstatus, status, morestatus
|
25 |
+
elif code.startswith("4"):
|
26 |
+
status = data['WebStatus']['Offline']['ClientError'][code]
|
27 |
+
code = code
|
28 |
+
webstatus = "Offline. Client-side Error or Unauthorization Error or Authentication Error."
|
29 |
+
status = status
|
30 |
+
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."
|
31 |
+
return code, webstatus, status, morestatus
|
32 |
+
elif code.startswith("5"):
|
33 |
+
status = data['WebStatus']['Offline']['ServerError'][code]
|
34 |
+
code = code
|
35 |
+
webstatus = "Offline"
|
36 |
+
status = status
|
37 |
+
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."
|
38 |
+
return code, webstatus, status, morestatus
|
39 |
+
else:
|
40 |
+
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."
|
41 |
+
except KeyError:
|
42 |
+
return "abc.", "def.", "ghi.", "jkl."
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
run()
|
requirements.txt
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.3.0
|
3 |
+
annotated-types==0.7.0
|
4 |
+
anyio==4.4.0
|
5 |
+
attrs==23.2.0
|
6 |
+
certifi==2024.6.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
colorama==0.4.6
|
10 |
+
contourpy==1.2.1
|
11 |
+
cycler==0.12.1
|
12 |
+
dnspython==2.6.1
|
13 |
+
email_validator==2.1.2
|
14 |
+
fastapi==0.111.0
|
15 |
+
fastapi-cli==0.0.4
|
16 |
+
ffmpy==0.3.2
|
17 |
+
filelock==3.15.1
|
18 |
+
fonttools==4.53.0
|
19 |
+
fsspec==2024.6.0
|
20 |
+
gradio==4.36.1
|
21 |
+
gradio_client==1.0.1
|
22 |
+
h11==0.14.0
|
23 |
+
httpcore==1.0.5
|
24 |
+
httptools==0.6.1
|
25 |
+
httpx==0.27.0
|
26 |
+
huggingface-hub==0.23.4
|
27 |
+
idna==3.7
|
28 |
+
importlib_resources==6.4.0
|
29 |
+
Jinja2==3.1.4
|
30 |
+
jsonschema==4.22.0
|
31 |
+
jsonschema-specifications==2023.12.1
|
32 |
+
kiwisolver==1.4.5
|
33 |
+
markdown-it-py==3.0.0
|
34 |
+
MarkupSafe==2.1.5
|
35 |
+
matplotlib==3.9.0
|
36 |
+
mdurl==0.1.2
|
37 |
+
numpy==2.0.0
|
38 |
+
orjson==3.10.5
|
39 |
+
packaging==24.1
|
40 |
+
pandas==2.2.2
|
41 |
+
pillow==10.3.0
|
42 |
+
pydantic==2.7.4
|
43 |
+
pydantic_core==2.18.4
|
44 |
+
pydub==0.25.1
|
45 |
+
Pygments==2.18.0
|
46 |
+
pyparsing==3.1.2
|
47 |
+
python-dateutil==2.9.0.post0
|
48 |
+
python-dotenv==1.0.1
|
49 |
+
python-multipart==0.0.9
|
50 |
+
pytz==2024.1
|
51 |
+
PyYAML==6.0.1
|
52 |
+
referencing==0.35.1
|
53 |
+
requests==2.32.3
|
54 |
+
rich==13.7.1
|
55 |
+
rpds-py==0.18.1
|
56 |
+
ruff==0.4.9
|
57 |
+
semantic-version==2.10.0
|
58 |
+
shellingham==1.5.4
|
59 |
+
six==1.16.0
|
60 |
+
sniffio==1.3.1
|
61 |
+
starlette==0.37.2
|
62 |
+
tomlkit==0.12.0
|
63 |
+
toolz==0.12.1
|
64 |
+
tqdm==4.66.4
|
65 |
+
typer==0.12.3
|
66 |
+
typing_extensions==4.12.2
|
67 |
+
tzdata==2024.1
|
68 |
+
ujson==5.10.0
|
69 |
+
urllib3==2.2.2
|
70 |
+
uvicorn==0.30.1
|
71 |
+
watchfiles==0.22.0
|
72 |
+
websockets==11.0.3
|
status.json
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"WebStatus": {
|
3 |
+
"Online": {
|
4 |
+
"SuccessfulConnection": {
|
5 |
+
"200": "Request was successful.",
|
6 |
+
"201": "Resource was created successfully.",
|
7 |
+
"202": "Request accepted, processing not complete.",
|
8 |
+
"203": "Request was successful, but information may be different.",
|
9 |
+
"204": "Request was successful, no content to return.",
|
10 |
+
"205": "Request was successful, reset the view.",
|
11 |
+
"206": "Request was successful, partial content returned.",
|
12 |
+
"207": "Request was successful, multiple statuses returned.",
|
13 |
+
"226": "Request was successful, and a transformation was applied."
|
14 |
+
},
|
15 |
+
"Redirection": {
|
16 |
+
"300": "Multiple options available.",
|
17 |
+
"301": "Resource moved permanently.",
|
18 |
+
"302": "Resource found, moved temporarily.",
|
19 |
+
"303": "Resource found at another location.",
|
20 |
+
"304": "Resource not modified, use cached version.",
|
21 |
+
"305": "Resource must be accessed through a proxy.",
|
22 |
+
"306": "Switch to a different proxy.",
|
23 |
+
"307": "Temporary redirect to another location.",
|
24 |
+
"308": "Permanent redirect to another location."
|
25 |
+
}
|
26 |
+
},
|
27 |
+
"Offline": {
|
28 |
+
"ClientError": {
|
29 |
+
"400": "Bad request due to client error.",
|
30 |
+
"401": "Unauthorized, authentication required.",
|
31 |
+
"402": "Payment required to access the resource.",
|
32 |
+
"403": "Forbidden, server refuses to respond.",
|
33 |
+
"404": "Resource not found.",
|
34 |
+
"405": "Method not allowed for this resource.",
|
35 |
+
"406": "Request not acceptable.",
|
36 |
+
"407": "Proxy authentication required.",
|
37 |
+
"408": "Request timed out.",
|
38 |
+
"409": "Conflict with current state of the resource.",
|
39 |
+
"410": "Resource no longer available.",
|
40 |
+
"411": "Content length required.",
|
41 |
+
"412": "Precondition failed.",
|
42 |
+
"413": "Payload too large.",
|
43 |
+
"414": "URI too long.",
|
44 |
+
"415": "Unsupported media type.",
|
45 |
+
"416": "Requested range not satisfiable.",
|
46 |
+
"417": "Expectation failed.",
|
47 |
+
"418": "I'm a teapot (joke response).",
|
48 |
+
"421": "Misdirected request.",
|
49 |
+
"422": "Unprocessable entity.",
|
50 |
+
"423": "Resource is locked.",
|
51 |
+
"424": "Failed dependency.",
|
52 |
+
"425": "Too early.",
|
53 |
+
"426": "Upgrade required.",
|
54 |
+
"428": "Precondition required.",
|
55 |
+
"429": "Too many requests.",
|
56 |
+
"431": "Request header fields too large.",
|
57 |
+
"451": "Unavailable due to legal reasons."
|
58 |
+
},
|
59 |
+
"ServerError": {
|
60 |
+
"500": "Internal server error.",
|
61 |
+
"501": "Not implemented.",
|
62 |
+
"502": "Bad gateway.",
|
63 |
+
"503": "Service unavailable.",
|
64 |
+
"504": "Gateway timeout.",
|
65 |
+
"505": "HTTP version not supported.",
|
66 |
+
"506": "Variant also negotiates.",
|
67 |
+
"507": "Insufficient storage.",
|
68 |
+
"508": "Loop detected.",
|
69 |
+
"510": "Not extended.",
|
70 |
+
"511": "Network authentication required."
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|