Updated parse_mana and symbology to the new refactor scheme.

This commit is contained in:
2018-03-03 18:31:30 -05:00
parent 240dcd7436
commit 5460d2b676
2 changed files with 28 additions and 47 deletions

View File

@ -28,50 +28,43 @@ class ParseMana(SymbologyObject):
self.url = 'symbology/parse-mana?cost=' + self.cost self.url = 'symbology/parse-mana?cost=' + self.cost
super(ParseMana, self).__init__(self.url) super(ParseMana, 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 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 mana_cost(self): def mana_cost(self):
if self.__checkForKey('cost') is None: self._checkForKey('cost')
raise KeyError('This object has no key \'cost\'')
return self.scryfallJson['cost'] return self.scryfallJson['cost']
def cmc(self): def cmc(self):
if self.__checkForKey('cmc') is None: self._checkForKey('cmc')
raise KeyError('This object has no key \'cmc\'')
return self.scryfallJson['cmc'] return self.scryfallJson['cmc']
def colors(self): def colors(self):
if self.__checkForKey('colors') is None: self._checkForKey('colors')
raise KeyError('This object has no key \'colors\'')
return self.scryfallJson['colors'] return self.scryfallJson['colors']
def colorless(self): def colorless(self):
if self.__checkForKey('colorless') is None: self._checkForKey('colorless')
raise KeyError('This object has no key \'colorless\'')
return self.scryfallJson['colorless'] return self.scryfallJson['colorless']
def monocolored(self): def monocolored(self):
if self.__checkForKey('monocolored') is None: self._checkForKey('monocolored')
raise KeyError('This object has no key \'monocolored\'')
return self.scryfallJson['monocolored'] return self.scryfallJson['monocolored']
def multicolored(self): def multicolored(self):
if self.__checkForKey('multicolored') is None: self._checkForKey('multicolored')
raise KeyError('This object has no key \'multicolored\'')
return self.scryfallJson['multicolored'] return self.scryfallJson['multicolored']

View File

@ -33,86 +33,74 @@ class Symbology(SymbologyObject):
self.url = 'symbology?' self.url = 'symbology?'
super(Symbology, self).__init__(self.url) super(Symbology, 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 ahs 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')
raise 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('has_more') is None: self._checkForKey('has_more')
raise 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 symbol_symbol(self, num): def symbol_symbol(self, num):
if self.__checkForTupleKey('data', num, 'symbol') is None: self._checkForTupleKey('data', num, 'symbol')
raise KeyError('This object has no key \'symbol\'')
return self.scryfallJson['data'][num]['symbol'] return self.scryfallJson['data'][num]['symbol']
def symbol_loose_variant(self, num): def symbol_loose_variant(self, num):
if self.__checkForTupleKey('data', num, 'loose_variant') is None: self._checkForTupleKey('data', num, 'loose_variant')
raise KeyError('This object has no key \'loose_variant\'')
return self.scryfallJson['data'][num]['loose_variant'] return self.scryfallJson['data'][num]['loose_variant']
def symbol_transposable(self, num): def symbol_transposable(self, num):
if self.__checkForTupleKey('data', num, 'transposable') is None: self._checkForTupleKey('data', num, 'transposable')
raise KeyError('This object has no key \'transposable\'')
return self.scryfallJson['data'][num]['transposable'] return self.scryfallJson['data'][num]['transposable']
def symbol_represents_mana(self, num): def symbol_represents_mana(self, num):
if self.__checkForTupleKey('data', num, 'represents_mana') is None: self._checkForTupleKey('data', num, 'represents_mana')
raise KeyError('This object has no key \'represents_mana\'')
return self.scryfallJson['data'][num]['represents_mana'] return self.scryfallJson['data'][num]['represents_mana']
def symbol_cmc(self, num): def symbol_cmc(self, num):
if self.__checkForTupleKey('data', num, 'cmc') is None: self._checkForTupleKey('data', num, 'cmc')
raise KeyError('This object has no key \'cmc\'')
return self.scryfallJson['data'][num]['cmc'] return self.scryfallJson['data'][num]['cmc']
def symbol_appears_in_mana_costs(self, num): def symbol_appears_in_mana_costs(self, num):
if self.__checkForTupleKey('data', num, 'appears_in_mana_costs') is None: self._checkForTupleKey('data', num, 'appears_in_mana_costs')
raise KeyError('This object has no key \'appears_in_mana_costs\'')
return self.scryfallJson['data'][num]['appears_in_mana_costs'] return self.scryfallJson['data'][num]['appears_in_mana_costs']
def symbol_funny(self, num): def symbol_funny(self, num):
if self.__checkForTupleKey('data', num, 'funny') is None: self._checkForTupleKey('data', num, 'funny')
raise KeyError('This object has no key \'funny\'')
return self.scryfallJson['data'][num]['funny'] return self.scryfallJson['data'][num]['funny']
def symbol_colors(self, num): def symbol_colors(self, num):
if self.__checkForTupleKey('data', num, 'colors') is None: self._checkForTupleKey('data', num, 'colors')
raise KeyError('This object has no key \'colors\'')
return self.scryfallJson['data'][num]['colors'] return self.scryfallJson['data'][num]['colors']