Skip to content

Commit ce2cab0

Browse files
committed
DAY 4 OF 14 PYTHON CHALLENGE
1 parent 7c9945e commit ce2cab0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import requests
3+
4+
def restart():
5+
answer = str(input("Do you want to start over? y/n ")).lower()
6+
if answer == "y" or answer == "n":
7+
if answer == "y":
8+
main()
9+
else:
10+
print("OK. Bye!")
11+
return
12+
else:
13+
print("That's not a valid answer. Please answer `y` or `n`")
14+
restart()
15+
16+
17+
def main():
18+
os.system("clear")
19+
print("Welcome to IsItDown.py!\nPlease write a URL or URLs you want to check. (separated by comma)")
20+
URLs = str(input()).lower().split(",")
21+
for URL in URLs:
22+
URL = URL.strip()
23+
if "." not in URL:
24+
print(URL, "is not a valid URL.")
25+
else:
26+
if "http" not in URL:
27+
URL = f"http://{URL}"
28+
try:
29+
request = requests.get(URL)
30+
if request.status_code == 200:
31+
print(URL, "is up!")
32+
else:
33+
print(URL, "is down!")
34+
except:
35+
print(URL, "is down!")
36+
restart()
37+
38+
main()

0 commit comments

Comments
 (0)