Skip to content

Instantly share code, notes, and snippets.

@ameesters
Created October 25, 2012 14:35
Show Gist options
  • Save ameesters/3952890 to your computer and use it in GitHub Desktop.
Save ameesters/3952890 to your computer and use it in GitHub Desktop.
A python script that checks multiple websites status.
#!/usr/bin/env python
import os, time, httplib
from termcolor import colored
SITES = [
"www.meesters-id.nl",
"www.carolsingers.nl",
]
while 1:
for site in SITES:
conn = httplib.HTTPConnection(site, timeout=10)
conn.request("HEAD", "/")
response = conn.getresponse()
if response.status != 200:
print "\a"
response.status = colored(response.status, 'red')
print "{0:30} {1:10} {2:10}".format(site, response.status, response.reason)
conn.close()
time.sleep(2)
os.system("clear")
@tphe
Copy link

tphe commented Nov 11, 2020

You can also choose to handle a timeout error:

def get_status(site):

try:
    response = requests.head(site, timeout=1)
    status_code = response.status_code
    reason = response.reason
except requests.exceptions.ConnectionError:
    status_code = '000'
    reason = 'ConnectionError'
**except requests.exceptions.ReadTimeout:
    status_code = '001'
    reason = 'TimeOut'**
website_status = WebsiteStatus(status_code, reason)
return website_status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment