Skip to content

Commit

Permalink
Website status checker (Py-Contributors#201)
Browse files Browse the repository at this point in the history
* Add script to check status of web address

* flake8 fix and update README.md

* Flake8 fix
mikek4233 authored Oct 6, 2020
1 parent b1b2058 commit 5b634d6
Showing 2 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions website_status_checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Website Status Checker

This script will check the status of the web address which you will input

## Installation

- Install Python to your system if it's not available.

**Now you are ready to run the code**

## Note:

- Copy the file **website_status_checker.py** and store it in any folder or Desktop.

## Steps to run:

- Open the **website_status_checker.py** file i.e run it.
- To run it, you can open command prompt/shell/terminal in the containing folder and type the following command:
```
python website_status_checker.py
```
## Output:
The Status Code of the Website
## Contributor
- **Michael Kossowsky (https://github.com/mikek4233)**
39 changes: 39 additions & 0 deletions website_status_checker/website_status_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import urllib.request


def check_website_status():
prompt = "Please enter a website URL: "
while True:
# asks for URL to check
# adds in https or http if necessary
url = str(input(prompt))
if url.startswith('https://'):
pass
elif url.startswith('http://'):
pass
else:
url = 'https://' + url
try:
# tries to make a request to the URL that was input
# uses defined headers that are not a "bot"
headers = {}
headers['User-Agent'] = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \
(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
req = urllib.request.Request(url, headers=headers)
page = urllib.request.urlopen(req)
code = str(page.getcode())
print('The website ' + url + ' has returned a ' + code + ' code')
break
except Exception as e:
# if there is an error it will ask if you want to try again
print(str(e))
print("Make sure you are entering a valid URL")
try_again = input("Do you want to try again (y/n): ")
try_again = try_again.lower()
if try_again == 'y':
continue
else:
break


check_website_status()

0 comments on commit 5b634d6

Please sign in to comment.