From 5460d2b6763f98081288d0bc6aa66e497423265a Mon Sep 17 00:00:00 2001 From: Date: Sat, 3 Mar 2018 18:31:30 -0500 Subject: [PATCH] Updated parse_mana and symbology to the new refactor scheme. --- scrython/symbology/parse_mana.py | 27 +++++++----------- scrython/symbology/symbology.py | 48 ++++++++++++-------------------- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/scrython/symbology/parse_mana.py b/scrython/symbology/parse_mana.py index 3eab781..951b409 100644 --- a/scrython/symbology/parse_mana.py +++ b/scrython/symbology/parse_mana.py @@ -28,50 +28,43 @@ class ParseMana(SymbologyObject): self.url = 'symbology/parse-mana?cost=' + self.cost super(ParseMana, self).__init__(self.url) - def __checkForKey(self, key): + def _checkForKey(self, key): try: return self.scryfallJson[key] - except KeyError: - return None + except Exception: + raise KeyError('This object has no key \'{}\''.format(key)) def object(self): - if self.__checkForKey('object') is None: - raise KeyError('This object has no key \'object\'') + self._checkForKey('object') return self.scryfallJson['object'] def mana_cost(self): - if self.__checkForKey('cost') is None: - raise KeyError('This object has no key \'cost\'') + self._checkForKey('cost') return self.scryfallJson['cost'] def cmc(self): - if self.__checkForKey('cmc') is None: - raise KeyError('This object has no key \'cmc\'') + self._checkForKey('cmc') return self.scryfallJson['cmc'] def colors(self): - if self.__checkForKey('colors') is None: - raise KeyError('This object has no key \'colors\'') + self._checkForKey('colors') return self.scryfallJson['colors'] def colorless(self): - if self.__checkForKey('colorless') is None: - raise KeyError('This object has no key \'colorless\'') + self._checkForKey('colorless') return self.scryfallJson['colorless'] def monocolored(self): - if self.__checkForKey('monocolored') is None: - raise KeyError('This object has no key \'monocolored\'') + self._checkForKey('monocolored') return self.scryfallJson['monocolored'] def multicolored(self): - if self.__checkForKey('multicolored') is None: - raise KeyError('This object has no key \'multicolored\'') + self._checkForKey('multicolored') return self.scryfallJson['multicolored'] diff --git a/scrython/symbology/symbology.py b/scrython/symbology/symbology.py index ccc2acf..1331368 100644 --- a/scrython/symbology/symbology.py +++ b/scrython/symbology/symbology.py @@ -33,86 +33,74 @@ class Symbology(SymbologyObject): self.url = 'symbology?' super(Symbology, self).__init__(self.url) - def __checkForKey(self, key): + def _checkForKey(self, key): try: return self.scryfallJson[key] - except KeyError: - return None + except Exception: + raise KeyError('This object ahs no key \'{}\''.format(key)) - def __checkForTupleKey(self, parent, num, key): + def _checkForTupleKey(self, parent, num, key): try: return self.scryfallJson[parent][num][key] - except KeyError: - return None + except Exception: + raise KeyError('This object has no key \'{}\''.format(key)) def object(self): - if self.__checkForKey('object') is None: - raise KeyError('This object has no key \'object\'') + self._checkForKey('object') return self.scryfallJson['object'] def has_more(self): - if self.__checkForKey('has_more') is None: - raise KeyError('This object has no key \'has_more\'') + self._checkForKey('has_more') return self.scryfallJson['has_more'] def data(self): - if self.__checkForKey('has_more') is None: - raise KeyError('This object has no key \'data\'') + self._checkForKey('has_more') return self.scryfallJson['data'] def data_length(self): - if self.__checkForKey('data') is None: - return KeyError('This object has no key \'data\'') + self._checkForKey('data') return len(self.scryfallJson['data']) def symbol_symbol(self, num): - if self.__checkForTupleKey('data', num, 'symbol') is None: - raise KeyError('This object has no key \'symbol\'') + self._checkForTupleKey('data', num, 'symbol') return self.scryfallJson['data'][num]['symbol'] def symbol_loose_variant(self, num): - if self.__checkForTupleKey('data', num, 'loose_variant') is None: - raise KeyError('This object has no key \'loose_variant\'') + self._checkForTupleKey('data', num, 'loose_variant') return self.scryfallJson['data'][num]['loose_variant'] def symbol_transposable(self, num): - if self.__checkForTupleKey('data', num, 'transposable') is None: - raise KeyError('This object has no key \'transposable\'') + self._checkForTupleKey('data', num, 'transposable') return self.scryfallJson['data'][num]['transposable'] def symbol_represents_mana(self, num): - if self.__checkForTupleKey('data', num, 'represents_mana') is None: - raise KeyError('This object has no key \'represents_mana\'') + self._checkForTupleKey('data', num, 'represents_mana') return self.scryfallJson['data'][num]['represents_mana'] def symbol_cmc(self, num): - if self.__checkForTupleKey('data', num, 'cmc') is None: - raise KeyError('This object has no key \'cmc\'') + self._checkForTupleKey('data', num, 'cmc') return self.scryfallJson['data'][num]['cmc'] def symbol_appears_in_mana_costs(self, num): - if self.__checkForTupleKey('data', num, 'appears_in_mana_costs') is None: - raise KeyError('This object has no key \'appears_in_mana_costs\'') + self._checkForTupleKey('data', num, 'appears_in_mana_costs') return self.scryfallJson['data'][num]['appears_in_mana_costs'] def symbol_funny(self, num): - if self.__checkForTupleKey('data', num, 'funny') is None: - raise KeyError('This object has no key \'funny\'') + self._checkForTupleKey('data', num, 'funny') return self.scryfallJson['data'][num]['funny'] def symbol_colors(self, num): - if self.__checkForTupleKey('data', num, 'colors') is None: - raise KeyError('This object has no key \'colors\'') + self._checkForTupleKey('data', num, 'colors') return self.scryfallJson['data'][num]['colors']