X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/calendar?a=blobdiff_plain;f=plomlombot.py;h=126323f299717581e097b56fa8d449ca4f65d560;hb=937110c667bb079367a14581a4853d68c6be2f40;hp=e4a5be35aabd091204209eff379a542f206c7e4e;hpb=61a573d1cb2165c5aa7a00b999b9b5bda81caaaa;p=plomlombot-irc.git diff --git a/plomlombot.py b/plomlombot.py index e4a5be3..126323f 100644 --- a/plomlombot.py +++ b/plomlombot.py @@ -71,52 +71,66 @@ class IO: line) return line -def url_check(msg): - matches = re.findall("(https?://[^\s]+)", msg) - for i in range(len(matches)): - url = matches[i] - webpage = urllib.request.urlopen(url, timeout=15) - content_type = webpage.info().get_content_type() - charset = webpage.info().get_content_charset() - if not charset: - charset="utf-8" - if not content_type in ('text/html', 'text/xml', - 'application/xhtml+xml'): - print("TROUBLE INTERPRETING URL: bad content_type " + content_type) +def lineparser_loop(): + + def act_on_privmsg(tokens): + + def url_check(msg): + matches = re.findall("(https?://[^\s]+)", msg) + for i in range(len(matches)): + url = matches[i] + try: + webpage = urllib.request.urlopen(url, timeout=15) + except urllib.error.HTTPError as error: + print("TROUBLE FOLLOWING URL: " + str(error)) + continue + charset = webpage.info().get_content_charset() + if not charset: + charset="utf-8" + content_type = webpage.info().get_content_type() + if not content_type in ('text/html', 'text/xml', + 'application/xhtml+xml'): + print("TROUBLE INTERPRETING URL: bad content type " + + content_type) + continue + content = webpage.read().decode(charset) + title = str(content).split('