Catch exceptions thrown by the title module
Diff
dave/modules/title.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
@@ -6,6 +6,7 @@
from requests import get
from twisted.words.protocols.irc import assembleFormattedText, attributes as A
import dave.config
from twisted.python import log
parse = re.compile(r"(?:(?:https?):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?", re.IGNORECASE)
@@ -18,8 +19,12 @@
for match in matches:
if not dave.config.redis.exists("site:{}".format(match)):
res = get(match, timeout=3,
headers={'user-agent': 'irc bot (https://github.com/w4)'})
try:
res = get(match, timeout=3,
headers={'user-agent': 'irc bot (https://github.com/w4)'})
except BaseException as e:
log.msg("Couldn't connect to host.", e)
return
if res.encoding == 'ISO-8859-1' and not 'ISO-8859-1' in \