X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/gitweb.css?a=blobdiff_plain;ds=inline;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('