IrcMiRCARTBot.py:IrcMiRCARTBot._dispatchPrivmsg(): catch urllib.error.HTTPError exception during download.

IrcMiRCARTBot.py:IrcMiRCARTBot._dispatchPrivmsg(): fix typo.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-03 04:24:18 +01:00
parent 95b706b4bd
commit f2affda37e

View File

@ -117,7 +117,12 @@ class IrcMiRCARTBot(IrcClient.IrcClient):
os.remove(asciiTmpFilePath) os.remove(asciiTmpFilePath)
if os.path.isfile(imgTmpFilePath): if os.path.isfile(imgTmpFilePath):
os.remove(imgTmpFilePath) os.remove(imgTmpFilePath)
urllib.request.urlretrieve(asciiUrl, asciiTmpFilePath) try:
urllib.request.urlretrieve(asciiUrl, asciiTmpFilePath)
except urllib.error.HTTPError as err:
self._log("Download failed with HTTP status code {}".format(err.code))
self.queue("PRIVMSG", message[2], "4/!\\ Download failed with HTTP status code {}!".format(err.code))
return
_MiRCART = MiRCART.MiRCART(asciiTmpFilePath, imgTmpFilePath, "DejaVuSansMono.ttf", 11) _MiRCART = MiRCART.MiRCART(asciiTmpFilePath, imgTmpFilePath, "DejaVuSansMono.ttf", 11)
imgurResponse = self._uploadToImgur(imgTmpFilePath, "MiRCART image", "MiRCART image", "c9a6efb3d7932fd") imgurResponse = self._uploadToImgur(imgTmpFilePath, "MiRCART image", "MiRCART image", "c9a6efb3d7932fd")
if imgurResponse[0] == 200: if imgurResponse[0] == 200:
@ -125,7 +130,7 @@ class IrcMiRCARTBot(IrcClient.IrcClient):
self.queue("PRIVMSG", message[2], "8/!\\ Uploaded as: {}".format(imgurResponse[1])) self.queue("PRIVMSG", message[2], "8/!\\ Uploaded as: {}".format(imgurResponse[1]))
else: else:
self._log("Upload failed with HTTP status code {}".format(imgurResponse[0])) self._log("Upload failed with HTTP status code {}".format(imgurResponse[0]))
self.queue("PRIVMSG", message[2], "4/!\\ Uploaded failed with HTTP status code {}!".format(imgurResponse[0])) self.queue("PRIVMSG", message[2], "4/!\\ Upload failed with HTTP status code {}!".format(imgurResponse[0]))
if os.path.isfile(asciiTmpFilePath): if os.path.isfile(asciiTmpFilePath):
os.remove(asciiTmpFilePath) os.remove(asciiTmpFilePath)
if os.path.isfile(imgTmpFilePath): if os.path.isfile(imgTmpFilePath):