down.py -- a better implementation

This commit is contained in:
Ryan Hitchman 2009-07-09 23:39:37 -06:00
parent 59a14e363e
commit 5bd945b7c1
2 changed files with 24 additions and 16 deletions

24
plugins/down.py Normal file
View File

@ -0,0 +1,24 @@
import urllib2
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
# http://mail.python.org/pipermail/python-list/2006-December/589854.html
try:
request = urllib2.Request(inp)
request.get_method = lambda: "HEAD"
http_file = urllib2.urlopen(request, timeout=10)
head = http_file.headers
return 'it seems to be up'
except urllib2.URLError:
return 'it seems to be down'

View File

@ -1,16 +0,0 @@
from lxml import html
from util import hook
import urllib
@hook.command
def down(inp):
'''.down <url> -- checks http://downforeveryoneorjustme.com to see if the site is down'''
url = 'http://downforeveryoneorjustme.com/' + urllib.quote(inp.strip(), safe='')
page = html.parse(url)
status = page.xpath("//title")[0].text_content()
return status
#local testing
#print down("googlelakj.com")