From 6121002b351a5016150299d22a84e937d9ae35a4 Mon Sep 17 00:00:00 2001 From: Shivam Gera Date: Thu, 28 Dec 2017 22:50:24 +0530 Subject: [PATCH] Update giphy.py --- zulip_bots/zulip_bots/bots/giphy/giphy.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/zulip_bots/zulip_bots/bots/giphy/giphy.py b/zulip_bots/zulip_bots/bots/giphy/giphy.py index f49812b..8a3369b 100644 --- a/zulip_bots/zulip_bots/bots/giphy/giphy.py +++ b/zulip_bots/zulip_bots/bots/giphy/giphy.py @@ -5,6 +5,7 @@ import logging import sys import os import re +from requests.exceptions import HTTPError, ConnectionError GIPHY_TRANSLATE_API = 'http://api.giphy.com/v1/gifs/translate' @@ -25,6 +26,19 @@ class GiphyHandler(object): def initialize(self, bot_handler: Any) -> None: self.config_info = bot_handler.get_config_info('giphy') + query = {'test': 'keyword', + 'api_key': self.config_info['key']} + try: + data = requests.get(GIPHY_TRANSLATE_API, params=query) + except HTTPError as e: + if (e.response.json()['error']['errors'][0]['reason'] == 'keyInvalid'): + logging.error('Invalid key.' + 'Follow the instructions in doc.md for setting API key.') + sys.exit(1) + else: + raise + except ConnectionError: + logging.warning('Bad connection') def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None: bot_response = get_bot_giphy_response(