-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite.py
38 lines (30 loc) · 1023 Bytes
/
website.py
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
import requests
import time
checking = True
def main():
website_url = input_website_url()
while checking:
check_website_status(website_url)
time.sleep(60)
#again = input("Do you want to check another website? (y/n): ").lower()
if not checking:
break
print("Goodbye!")
def check_website_status(url):
global checking
try:
response = requests.get(url)
# Check if the status code is in the 2xx range
if response.status_code // 100 == 2:
print(f"The website {url} is up and running.")
else:
print(f"The website {url} is down. Status code: {response.status_code}")
checking = False
except requests.ConnectionError:
print(f"Failed to connect to {url}. The website may be down.")
checking = False
def input_website_url():
website_url = input("Enter the website URL: https://www.")
return ("https://www."+website_url)
if __name__ == "__main__":
main()