From 06c5ab6e3a43f8c36b3d8ab03b4f5326dd8416c7 Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Wed, 25 Sep 2019 06:56:31 +0300 Subject: [PATCH 1/3] Fix issue where prices are now a nested dictionary --- scrython/cards/cards_object.py | 4 ++-- scrython/foundation.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scrython/cards/cards_object.py b/scrython/cards/cards_object.py index 38dac2b..71896c8 100644 --- a/scrython/cards/cards_object.py +++ b/scrython/cards/cards_object.py @@ -475,9 +475,9 @@ class CardsObject(FoundationObject): if mode not in modes: 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): """A dictionary of related websites for this card diff --git a/scrython/foundation.py b/scrython/foundation.py index 9b984a6..0b4a2b7 100644 --- a/scrython/foundation.py +++ b/scrython/foundation.py @@ -30,7 +30,7 @@ class FoundationObject(object): if self.scryfallJson['object'] == 'error': raise Exception(self.scryfallJson['details']) - def _checkForKey(self, key): + def _checkForKey(self, key, nested_key=None): """Checks for a key in the scryfallJson object. This function should be considered private, and should not be accessed in production. @@ -44,6 +44,11 @@ class FoundationObject(object): if not key in self.scryfallJson: 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): """Checks for a key of an object in an array. This function should be considered private, and From 9fd74649bf3bde70c385245a975c65fbf412fac3 Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Wed, 25 Sep 2019 07:10:10 +0300 Subject: [PATCH 2/3] scryfall seems to now give a list frame_effects rather than a single frame_effect --- scrython/cards/cards_object.py | 8 ++++---- unittests/TestCards.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scrython/cards/cards_object.py b/scrython/cards/cards_object.py index 71896c8..ece7a8b 100644 --- a/scrython/cards/cards_object.py +++ b/scrython/cards/cards_object.py @@ -419,15 +419,15 @@ class CardsObject(FoundationObject): return self.scryfallJson['frame'] - def frame_effect(self): + def frame_effects(self): """The card's frame effect, if any. (miracle, nyxtouched, etc.) Returns: - string: The card's frame effect. + list: The card's frame effects. """ - super(CardsObject, self)._checkForKey('frame_effect') + super(CardsObject, self)._checkForKey('frame_effects') - return self.scryfallJson['frame_effect'] + return self.scryfallJson['frame_effects'] def full_art(self): """Returns True if the card is considered full art diff --git a/unittests/TestCards.py b/unittests/TestCards.py index daeff35..bc163f4 100644 --- a/unittests/TestCards.py +++ b/unittests/TestCards.py @@ -240,8 +240,8 @@ class TestSearch(unittest.TestCase): def test_tcgplayer_id(self): self.assertIsInstance(non_online_card.tcgplayer_id(), int) - def test_frame_effect(self): - self.assertIsInstance(transform.frame_effect(), str) + def test_frame_effects(self): + self.assertIsInstance(transform.frame_effects(), list) def test_games(self): self.assertIsInstance(non_online_card.games(), list) From 25759904037b3d9055b9dc20c39413a4862f4ea4 Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Wed, 25 Sep 2019 07:13:50 +0300 Subject: [PATCH 3/3] add usd_foil as a mode option to prices --- scrython/cards/cards_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrython/cards/cards_object.py b/scrython/cards/cards_object.py index ece7a8b..9b518ca 100644 --- a/scrython/cards/cards_object.py +++ b/scrython/cards/cards_object.py @@ -471,7 +471,7 @@ class CardsObject(FoundationObject): Returns: float: The prices as a float """ - modes = ['usd', 'eur', 'tix'] + modes = ['usd', 'usd_foil', 'eur', 'tix'] if mode not in modes: raise KeyError("{} is not a key.".format(mode))