diff --git a/modules/networking/isup.py b/modules/networking/isup.py index 6db94e1..f400381 100644 --- a/modules/networking/isup.py +++ b/modules/networking/isup.py @@ -1,6 +1,6 @@ -import json import urllib +from tools.web import getJSON def isup(url): """Determine if the given URL is up or not @@ -13,9 +13,7 @@ def isup(url): if o.netloc == "": o = urllib.parse.urlparse("http://" + url) if o.netloc != "": - req = urllib.request.Request("http://isitup.org/%s.json" % (o.netloc), headers={ 'User-Agent' : "nemubot v3" }) - raw = urllib.request.urlopen(req, timeout=10) - isup = json.loads(raw.read().decode()) + isup = getJSON("http://isitup.org/%s.json" % o.netloc) if "status_code" in isup and isup["status_code"] == 1: return isup["response_time"] diff --git a/modules/networking/whois.py b/modules/networking/whois.py index f5f29f0..2ec51ed 100644 --- a/modules/networking/whois.py +++ b/modules/networking/whois.py @@ -1,9 +1,8 @@ import datetime -import json -import socket import urllib from more import Response +from tools.web import getJSON URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?rid=1&domainName=%%s&outputFormat=json&userName=%s&password=%s" @@ -80,15 +79,7 @@ def cmd_whois(msg): dom = msg.cmds[1] - try: - req = urllib.request.Request(URL_WHOIS % urllib.parse.quote(dom), headers={ 'User-Agent' : "nemubot v3" }) - raw = urllib.request.urlopen(req, timeout=10) - except socket.timeout: - raise IRCException("Sorry, the request has timed out.") - except urllib.error.HTTPError as e: - raise IRCException("HTTP error occurs: %s %s" % (e.code, e.reason)) - - js = json.loads(raw.read().decode()) + js = getJSON(URL_WHOIS % urllib.parse.quote(dom)) if "ErrorMessage" in js: err = js["ErrorMessage"]