Add proper error handling on get_title

This commit is contained in:
Robert Miles 2018-11-18 16:38:16 -05:00
parent 34557b7888
commit 1a64668191
1 changed files with 8 additions and 4 deletions

12
bot.py
View File

@ -7,10 +7,14 @@ PUBLIC_COMMANDS = ["sotd","listsotd"]
SOTDS = datastore.DataStore("sotd.json")
def get_title(link):
title = str(urlopen(link).read()).split("<title>", 1)[1].split("</title>", 1)[0]
if "YouTube" in title:
return title.split(" - YouTube", 1)[0]
return title
try:
title = str(urlopen(link).read()).split("<title>", 1)[1].split("</title>", 1)[0]
if "YouTube" in title:
return title.split(" - YouTube", 1)[0]
return title
except:
print(e)
return link
class SOTDBot(teambot.Handler,teambot.CommandHandlerMixin):
def __init__(self,*args):