From 50e9d35064669b402c56cf0942ab9ac16fe73655 Mon Sep 17 00:00:00 2001 From: Date: Sat, 3 Mar 2018 12:29:37 -0500 Subject: [PATCH] Created data_length and data_tuple attributes for Search --- scrython/cards/search.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scrython/cards/search.py b/scrython/cards/search.py index 0faf90b..29ac880 100644 --- a/scrython/cards/search.py +++ b/scrython/cards/search.py @@ -53,6 +53,12 @@ class Search(CardsObject): except KeyError: return None + def __checkForTupleKey(self, parent, num, key): + try: + return self.scryfallJson[parent][num][key] + except KeyError: + return None + def object(self): if self.__checkForKey('object') is None: raise KeyError('This object has no key \'object\'') @@ -83,6 +89,18 @@ class Search(CardsObject): return self.scryfallJson['warnings'] + def data_length(self): + if self.__checkForKey('data') is None: + raise KeyError('This object has no key \'data\'') + + return len(self.scryfallJson['data']) + + def data_tuple(self, num): + if self.__checkForKey('data') is None: + raise KeyError('This object has no key \'data\'') + + return self.scryfallJson['data'][num] + #The following attributes are only to override the inherited class attributes. #This class has no matching attributes but we still need the getRequest function from CardsObject