Skip to content

updated comments to code #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions website_status_check/website_status_check.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import urllib2
import socket
import urllib2 #importing library urllib2 (which user might need to install before running the script)
import socket #importing socket

def check_url( url, timeout=10 ):
httpcode =1
if urllib2.urlopen(url,timeout=timeout).getcode() == 200:
return "website is online"
elif urllib2.urlopen(url,timeout=timeout).getcode() == 301:
return "website was redirected permaanently"
elif urllib2.urlopen(url,timeout=timeout).getcode() == 404:
return "website was not found"
print "please enter a website to check the status. don`t forget to add the http://"
site = raw_input()
print check_url(site)
def check_url( url, timeout=10 ): #creating function to keep code orginized
if urllib2.urlopen(url,timeout=timeout).getcode() == 200: #this is checking if the return request of urllib2 is 200 which means website is online
return "website is online" #returns a string
elif urllib2.urlopen(url,timeout=timeout).getcode() == 301: #this is checking if the return request of urllib2 is 301 which means website has been permanently redirected
return "website was redirected permanently" #returns a string
elif urllib2.urlopen(url,timeout=timeout).getcode() == 404: #this is checking if the return request of urllib2 is 404 which means page was not found
return "website was not found" #returns a string
print "please enter a website to check the status. don`t forget to add the http://" #printing prompt line
site = raw_input() #input string was put into site as a variable
print check_url(site) #run function with given variable