From e091920bda5ec3f40af3f60e0a8da2f5ff9acb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Tue, 2 Jan 2018 21:57:21 +0100 Subject: [PATCH] pngbot.py: handle HTTP status codes differing from 200. pngbot.py: update IRC message text. --- pngbot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pngbot.py b/pngbot.py index afddc1a..5bc33b7 100755 --- a/pngbot.py +++ b/pngbot.py @@ -115,8 +115,11 @@ def main(argv0, ircServerHname, ircServerPort="6667", ircClientNick="pngbot", ir _MiRCART = mirc2png.MiRCART(asciiTmpFilePath, imgTmpFilePath, "DejaVuSansMono.ttf", 11) imgurResponseHttp = requests.post("https://api.imgur.com/3/upload.json", data={"key":"c9a6efb3d7932fd", "image":base64.b64encode(open(imgTmpFilePath, "rb").read()), "type":"base64", "name":"tmp.png", "title":"tmp.png"}, headers={"Authorization": "Client-ID c9a6efb3d7932fd"}) imgurResponse = json.loads(imgurResponseHttp.text) - imgurResponseUrl = imgurResponse.get("data").get("link") - _IrcBot.sendline("PRIVMSG", ircServerMessage[2], "Uploaded as {}".format(imgurResponseUrl)) + if imgurResponse.status_code == 200: + imgurResponseUrl = imgurResponse.get("data").get("link") + _IrcBot.sendline("PRIVMSG", ircServerMessage[2], "8/!\\ Uploaded as: {}".format(imgurResponseUrl)) + else: + _IrcBot.sendline("PRIVMSG", ircServerMessage[2], "4/!\\ Uploaded failed with HTTP status code {}!".format(imgurResponse.status_code)) os.remove(asciiTmpFilePath); os.remove(imgTmpFilePath); if __name__ == "__main__":