2014-12-01 17:13:58 +00:00
|
|
|
import urllib
|
|
|
|
|
2015-01-03 19:34:44 +00:00
|
|
|
from nemubot.tools.web import getJSON
|
2014-12-01 17:13:58 +00:00
|
|
|
|
|
|
|
def isup(url):
|
|
|
|
"""Determine if the given URL is up or not
|
|
|
|
|
|
|
|
Argument:
|
|
|
|
url -- the URL to check
|
|
|
|
"""
|
|
|
|
|
|
|
|
o = urllib.parse.urlparse(url, "http")
|
|
|
|
if o.netloc == "":
|
|
|
|
o = urllib.parse.urlparse("http://" + url)
|
|
|
|
if o.netloc != "":
|
2014-12-15 22:57:37 +00:00
|
|
|
isup = getJSON("http://isitup.org/%s.json" % o.netloc)
|
2014-12-01 17:13:58 +00:00
|
|
|
if "status_code" in isup and isup["status_code"] == 1:
|
|
|
|
return isup["response_time"]
|
|
|
|
|
|
|
|
return None
|