Fix issue where prices are now a nested dictionary

This commit is contained in:
Dylan Stephano-Shachter 2019-09-25 06:56:31 +03:00
parent 49fd9bd112
commit 06c5ab6e3a
2 changed files with 8 additions and 3 deletions

View File

@ -475,9 +475,9 @@ class CardsObject(FoundationObject):
if mode not in modes: if mode not in modes:
raise KeyError("{} is not a key.".format(mode)) raise KeyError("{} is not a key.".format(mode))
super(CardsObject, self)._checkForKey(mode) super(CardsObject, self)._checkForKey('prices', mode)
return self.scryfallJson[mode] return self.scryfallJson['prices'][mode]
def related_uris(self): def related_uris(self):
"""A dictionary of related websites for this card """A dictionary of related websites for this card

View File

@ -30,7 +30,7 @@ class FoundationObject(object):
if self.scryfallJson['object'] == 'error': if self.scryfallJson['object'] == 'error':
raise Exception(self.scryfallJson['details']) raise Exception(self.scryfallJson['details'])
def _checkForKey(self, key): def _checkForKey(self, key, nested_key=None):
"""Checks for a key in the scryfallJson object. """Checks for a key in the scryfallJson object.
This function should be considered private, and This function should be considered private, and
should not be accessed in production. should not be accessed in production.
@ -44,6 +44,11 @@ class FoundationObject(object):
if not key in self.scryfallJson: if not key in self.scryfallJson:
raise KeyError('This card has no key \'{}\''.format(key)) raise KeyError('This card has no key \'{}\''.format(key))
if nested_key:
if not nested_key in self.scryfallJson[key]:
raise KeyError('This card has no key \'{}.{}\''.format(key, nested_key))
def _checkForTupleKey(self, parent, num, key): def _checkForTupleKey(self, parent, num, key):
"""Checks for a key of an object in an array. """Checks for a key of an object in an array.
This function should be considered private, and This function should be considered private, and