[title] Try to fix with certain sites

master
sfan5 2017-08-23 19:56:15 +02:00
parent 382e7cb15b
commit 8a432e905c
1 changed files with 4 additions and 6 deletions

View File

@ -23,16 +23,14 @@ def title(phenny, input):
data, sc = web.get(uri, 16384) data, sc = web.get(uri, 16384)
if sc != 200: if sc != 200:
return phenny.say("HTTP error %d" % sc) return phenny.say("HTTP error %d" % sc)
try:
data = str(data, 'utf-8') data = str(data, 'utf-8', 'ignore')
except UnicodeDecodeError:
return phenny.say("Doesn't seem to be HTML..")
m = re.search(r_title, data) m = re.search(r_title, data)
if not m: if not m:
return phenny.say("No title found.") return phenny.say("No title found.")
title = m.group(1) title = m.group(1)
title = html.unescape(title) title = html.unescape(title).strip()
title = title.strip()
if len(title) > 150: if len(title) > 150:
title = title[:150] + "[...]" title = title[:150] + "[...]"
phenny.reply(title) phenny.reply(title)