Updates sets to the new refactor scheme.

This commit is contained in:
2018-03-03 18:26:08 -05:00
parent 5276b70be9
commit 240dcd7436
1 changed files with 24 additions and 42 deletions

View File

@ -41,123 +41,105 @@ class Sets(SetsObject):
self._url = 'sets?' self._url = 'sets?'
super(Sets, self).__init__(self._url) super(Sets, self).__init__(self._url)
def __checkForKey(self, key): def _checkForKey(self, key):
try: try:
return self.scryfallJson[key] return self.scryfallJson[key]
except KeyError: except Exception:
return None raise KeyError('This object has no key \'{}\''.format(key))
def __checkForTupleKey(self, parent, num, key): def _checkForTupleKey(self, parent, num, key):
try: try:
return self.scryfallJson[parent][num][key] return self.scryfallJson[parent][num][key]
except KeyError: except Exception:
return None raise KeyError('This object has no key \'{}\''.format(key))
def object(self): def object(self):
if self.__checkForKey('object') is None: self._checkForKey('object')
raise KeyError('This object has no key \'object\'')
return self.scryfallJson['object'] return self.scryfallJson['object']
def has_more(self): def has_more(self):
if self.__checkForKey('has_more') is None: self._checkForKey('has_more')
return KeyError('This object has no key \'has_more\'')
return self.scryfallJson['has_more'] return self.scryfallJson['has_more']
def data(self): def data(self):
if self.__checkForKey('data') is None: self._checkForKey('data')
return KeyError('This object has no key \'data\'')
return self.scryfallJson['data'] return self.scryfallJson['data']
def data_length(self): def data_length(self):
if self.__checkForKey('data') is None: self._checkForKey('data')
return KeyError('This object has no key \'data\'')
return len(self.scryfallJson['data']) return len(self.scryfallJson['data'])
def set_object(self, num): def set_object(self, num):
if self.__checkForTupleKey('data', num, 'object') is None: self._checkForTupleKey('data', num, 'object')
return KeyError('This ruling has no key \'object\'')
return self.scryfallJson['data'][num]['object'] return self.scryfallJson['data'][num]['object']
def set_code(self, num): def set_code(self, num):
if self.__checkForTupleKey('data', num, 'code') is None: self._checkForTupleKey('data', num, 'code')
raise KeyError('This object has no key \'code\'')
return self.scryfallJson['data'][num]['code'] return self.scryfallJson['data'][num]['code']
def set_mtgo_code(self, num): def set_mtgo_code(self, num):
if self.__checkForTupleKey('data', num, 'mtgo_code') is None: self._checkForTupleKey('data', num, 'mtgo_code')
raise KeyError('This object has no key \'mtgo_code\'')
return self.scryfallJson['data'][num]['mtgo_code'] return self.scryfallJson['data'][num]['mtgo_code']
def set_name(self, num): def set_name(self, num):
if self.__checkForTupleKey('data', num, 'name') is None: self._checkForTupleKey('data', num, 'name')
raise KeyError('This object has no key \'name\'')
return self.scryfallJson['data'][num]['name'] return self.scryfallJson['data'][num]['name']
def set_set_type(self, num): def set_set_type(self, num):
if self.__checkForTupleKey('data', num, 'set_type') is None: self._checkForTupleKey('data', num, 'set_type')
raise KeyError('This object has no key \'set_type\'')
return self.scryfallJson['data'][num]['set_type'] return self.scryfallJson['data'][num]['set_type']
def set_released_at(self, num): def set_released_at(self, num):
if self.__checkForTupleKey('data', num, 'released_at') is None: self._checkForTupleKey('data', num, 'released_at')
raise KeyError('This object has no key \'released_at\'')
return self.scryfallJson['data'][num]['released_at'] return self.scryfallJson['data'][num]['released_at']
def set_block_code(self, num): def set_block_code(self, num):
if self.__checkForTupleKey('data', num, 'block_code') is None: self._checkForTupleKey('data', num, 'block_code')
raise KeyError('This object has no key \'block_code\'')
return self.scryfallJson['data'][num]['block_code'] return self.scryfallJson['data'][num]['block_code']
def set_block(self, num): def set_block(self, num):
if self.__checkForTupleKey('data', num, 'block') is None: self._checkForTupleKey('data', num, 'block')
raise KeyError('This object has no key \'block\'')
return self.scryfallJson['data'][num]['block'] return self.scryfallJson['data'][num]['block']
def set_parent_set_code(self, num): def set_parent_set_code(self, num):
if self.__checkForTupleKey('data', num, 'parent_set_code') is None: self._checkForTupleKey('data', num, 'parent_set_code')
raise KeyError('This object has no key \'parent_set_code\'')
return self.scryfallJson['data'][num]['parent_set_code'] return self.scryfallJson['data'][num]['parent_set_code']
def set_card_count(self, num): def set_card_count(self, num):
if self.__checkForTupleKey('data', num, 'card_count') is None: self._checkForTupleKey('data', num, 'card_count')
raise KeyError('This object has no key \'card_count\'')
return self.scryfallJson['data'][num]['card_count'] return self.scryfallJson['data'][num]['card_count']
def set_digital(self, num): def set_digital(self, num):
if self.__checkForTupleKey('data', num, 'digital') is None: self._checkForTupleKey('data', num, 'digital')
raise KeyError('This object has no key \'digital\'')
return self.scryfallJson['data'][num]['digital'] return self.scryfallJson['data'][num]['digital']
def set_foil(self, num): def set_foil(self, num):
if self.__checkForTupleKey('data', num, 'foil') is None: self._checkForTupleKey('data', num, 'foil')
raise KeyError('This object has no key \'foil\'')
return self.scryfallJson['data'][num]['foil'] return self.scryfallJson['data'][num]['foil']
def set_icon_svg_uri(self, num): def set_icon_svg_uri(self, num):
if self.__checkForTupleKey('data', num, 'icon_svg_uri') is None: self._checkForTupleKey('data', num, 'icon_svg_uri')
raise KeyError('This object has no key \'icon_svg_uri\'')
return self.scryfallJson['data'][num]['icon_svg_uri'] return self.scryfallJson['data'][num]['icon_svg_uri']
def set_search_uri(self, num): def set_search_uri(self, num):
if self.__checkForTupleKey('data', num, 'search_uri') is None: self._checkForTupleKey('data', num, 'search_uri')
raise KeyError('This object has no key \'search_uri\'')
return self.scryfallJson['data'][num]['search_uri'] return self.scryfallJson['data'][num]['search_uri']