2014-12-01 17:13:58 +00:00
|
|
|
import urllib
|
|
|
|
|
2015-10-13 22:17:02 +00:00
|
|
|
from nemubot.tools.web import getNormalizedURL, 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
|
|
|
|
"""
|
|
|
|
|
2015-10-13 22:17:02 +00:00
|
|
|
o = urllib.parse.urlparse(getNormalizedURL(url), "http")
|
2014-12-01 17:13:58 +00:00
|
|
|
if o.netloc != "":
|
2014-12-15 22:57:37 +00:00
|
|
|
isup = getJSON("http://isitup.org/%s.json" % o.netloc)
|
2015-07-05 11:09:18 +00:00
|
|
|
if isup is not None and "status_code" in isup and isup["status_code"] == 1:
|
2014-12-01 17:13:58 +00:00
|
|
|
return isup["response_time"]
|
|
|
|
|
|
|
|
return None
|