tools/web: factorize getNormalizedURL

This commit is contained in:
nemunaire 2015-10-14 00:17:02 +02:00
commit 55e6550cb1
7 changed files with 26 additions and 21 deletions

View file

@ -1,6 +1,6 @@
import urllib
from nemubot.tools.web import getJSON
from nemubot.tools.web import getNormalizedURL, getJSON
def isup(url):
"""Determine if the given URL is up or not
@ -9,7 +9,7 @@ def isup(url):
url -- the URL to check
"""
o = urllib.parse.urlparse(url, "http")
o = urllib.parse.urlparse(getNormalizedURL(url), "http")
if o.netloc != "":
isup = getJSON("http://isitup.org/%s.json" % o.netloc)
if isup is not None and "status_code" in isup and isup["status_code"] == 1:

View file

@ -21,7 +21,7 @@ def headers(url):
url -- the page URL to get header
"""
o = urllib.parse.urlparse(url, "http")
o = urllib.parse.urlparse(web.getNormalizedURL(url), "http")
if o.netloc == "":
raise IRCException("invalid URL")
if o.scheme == "http":

View file

@ -3,6 +3,7 @@ import urllib
from nemubot import __version__
from nemubot.exception import IRCException
from nemubot.tools.web import getNormalizedURL
def validator(url):
"""Run the w3c validator on the given URL
@ -11,7 +12,7 @@ def validator(url):
url -- the URL to validate
"""
o = urllib.parse.urlparse(url, "http")
o = urllib.parse.urlparse(getNormalizedURL(url), "http")
if o.netloc == "":
raise IRCException("Indicate a valid URL!")

View file

@ -8,10 +8,10 @@ from urllib.parse import urlparse
from nemubot.event import ModuleEvent
from nemubot.exception import IRCException
from nemubot.hooks import hook
from nemubot.tools.web import getNormalizedURL
from nemubot.tools.xmlparser.node import ModuleState
logger = logging.getLogger("nemubot.module.networking.watchWebsite")
nemubotversion = 3.4
from more import Response
@ -56,7 +56,7 @@ def del_site(url, nick, channel, frm_owner):
url -- URL to unwatch
"""
o = urlparse(url, "http")
o = urlparse(getNormalizedURL(url), "http")
if o.scheme != "" and url in DATAS.index:
site = DATAS.index[url]
for a in site.getNodes("alert"):
@ -80,7 +80,7 @@ def add_site(url, nick, channel, server, diffType="diff"):
url -- URL to watch
"""
o = urlparse(url, "http")
o = urlparse(getNormalizedURL(url), "http")
if o.netloc == "":
raise IRCException("sorry, I can't watch this URL :(")
@ -210,7 +210,7 @@ def start_watching(site, offset=0):
offset -- offset time to delay the launch of the first check
"""
o = urlparse(site["url"], "http")
o = urlparse(getNormalizedURL(site["url"]), "http")
#print_debug("Add %s event for site: %s" % (site["type"], o.netloc))
try: