From 5bd945b7c167a62979d6570fe10ca62ddc0d235e Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Thu, 9 Jul 2009 23:39:37 -0600 Subject: [PATCH] down.py -- a better implementation --- plugins/down.py | 24 ++++++++++++++++++++++++ plugins/downforeveryoneorjustme.py | 16 ---------------- 2 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 plugins/down.py delete mode 100644 plugins/downforeveryoneorjustme.py diff --git a/plugins/down.py b/plugins/down.py new file mode 100644 index 0000000..7293051 --- /dev/null +++ b/plugins/down.py @@ -0,0 +1,24 @@ +import urllib2 + +from util import hook + +@hook.command +def down(inp): + '''.down -- 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' diff --git a/plugins/downforeveryoneorjustme.py b/plugins/downforeveryoneorjustme.py deleted file mode 100644 index 662df54..0000000 --- a/plugins/downforeveryoneorjustme.py +++ /dev/null @@ -1,16 +0,0 @@ -from lxml import html -from util import hook -import urllib - -@hook.command -def down(inp): - '''.down -- 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") \ No newline at end of file