h/plugins/down.py

28 lines
679 B
Python
Raw Normal View History

2009-07-10 05:39:37 +00:00
import urllib2
2009-07-10 06:06:55 +00:00
import urlparse
2009-07-10 05:39:37 +00:00
from util import hook
@hook.command
def down(inp):
'''.down <url> -- checks to see if the site is down'''
inp = inp.strip()
if not inp:
return down.__doc__
if 'http://' not in inp:
inp = 'http://' + inp
2009-07-10 06:06:55 +00:00
inp = 'http://' + urlparse.urlparse(inp).netloc
2009-07-10 05:39:37 +00:00
# http://mail.python.org/pipermail/python-list/2006-December/589854.html
try:
request = urllib2.Request(inp)
request.get_method = lambda: "HEAD"
2009-07-10 06:06:55 +00:00
http_file = urllib2.urlopen(request)
head = http_file.read()
return inp + ' seems to be up'
2009-07-10 05:39:37 +00:00
except urllib2.URLError:
2009-07-10 06:06:55 +00:00
return inp + ' seems to be down'