From 7ab602cec7a05718576de49d51ca740bec1c91d4 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Tue, 30 Jan 2018 10:30:14 -0500 Subject: [PATCH] Updated autocomplete to be more consistent with the rest of cards. --- cards/autocomplete.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cards/autocomplete.py b/cards/autocomplete.py index ecddac2..40a8acf 100644 --- a/cards/autocomplete.py +++ b/cards/autocomplete.py @@ -1,5 +1,4 @@ import asyncio, aiohttp -import json class Autocomplete(object): """ cards/autocomplete @@ -32,16 +31,31 @@ class Autocomplete(object): params={'q':self.query, 'pretty':self.pretty, 'format':self.format})) if self.scryfallJson['object'] == 'error': - raise Exception(self.scryfallJson['details']) self.session.close() + raise Exception(self.scryfallJson['details']) self.session.close() + def __checkForKey(self, key): + try: + return self.scryfallJson[key] + except KeyError: + return None + def object(self): + if self.__checkForKey('object') is None: + return KeyError('This card has no associated object key.') + return self.scryfallJson['object'] def total_items(self): + if self.__checkForKey('total_items') is None: + return KeyError('This card has no associated total items key.') + return self.scryfallJson['total_items'] def data(self): + if self.__checkForKey('data') is None: + return KeyError('This card has no associated data key.') + return self.scryfallJson['data']