down.py -- a better implementation
This commit is contained in:
parent
59a14e363e
commit
5bd945b7c1
|
@ -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'
|
|
@ -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")
|
|
Loading…
Reference in New Issue