1
0
Fork 0
nemubot/modules/networking/isup.py

19 lines
476 B
Python
Raw Normal View History

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 != "":
isup = getJSON("https://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