diff --git a/cards/cardid.py b/cards/cardid.py index 73c098d..65d4a0b 100644 --- a/cards/cardid.py +++ b/cards/cardid.py @@ -1,4 +1,4 @@ -from scryfall_object import ScryfallObject +from .scryfall_object import ScryfallObject class Id(ScryfallObject): """ cards/:id diff --git a/cards/collector.py b/cards/collector.py index 776d50b..8fc2bf3 100644 --- a/cards/collector.py +++ b/cards/collector.py @@ -1,4 +1,4 @@ -from scryfall_object import ScryfallObject +from .scryfall_object import ScryfallObject class Collector(ScryfallObject): """ cards/:code/:collector_number diff --git a/cards/mtgo.py b/cards/mtgo.py index ee4aadb..ef267ed 100644 --- a/cards/mtgo.py +++ b/cards/mtgo.py @@ -1,4 +1,4 @@ -from scryfall_object import ScryfallObject +from .scryfall_object import ScryfallObject import urllib.parse class Mtgo(ScryfallObject): diff --git a/cards/multiverse.py b/cards/multiverse.py index 88e7ccc..28734ab 100644 --- a/cards/multiverse.py +++ b/cards/multiverse.py @@ -1,4 +1,4 @@ -from scryfall_object import ScryfallObject +from .scryfall_object import ScryfallObject class Multiverse(ScryfallObject): """ diff --git a/cards/named.py b/cards/named.py index 9df3d8a..7d9553f 100644 --- a/cards/named.py +++ b/cards/named.py @@ -1,4 +1,4 @@ -from scryfall_object import ScryfallObject +from .scryfall_object import ScryfallObject import urllib.parse class Named(ScryfallObject): diff --git a/cards/randomcard.py b/cards/randomcard.py index 68737e9..0bdc1ce 100644 --- a/cards/randomcard.py +++ b/cards/randomcard.py @@ -1,4 +1,4 @@ -from scryfall_object import ScryfallObject +from .scryfall_object import ScryfallObject class RandomCard(ScryfallObject): diff --git a/cards/scryfall_object.py b/cards/scryfall_object.py index 45db750..babe523 100644 --- a/cards/scryfall_object.py +++ b/cards/scryfall_object.py @@ -1,7 +1,6 @@ import aiohttp import asyncio - class ScryfallObject(object): """ Parameters: @@ -81,131 +80,270 @@ class ScryfallObject(object): self.session.close() + def __checkForKey(self, key): + try: + return self.scryfallJson[key] + except KeyError: + return None + def object(self): + if self.__checkForKey('object') is None: + return KeyError("This card has no associated object.") + return self.scryfallJson['object'] def id(self): + if self.__checkForKey('id') is None: + return KeyError("This card has no associated id.") + return self.scryfallJson['id'] def multiverse_ids(self): + if self.__checkForKey('multiverse_ids') is None: + return KeyError("This card has no associated multiverse id.") + return self.scryfallJson['multiverse_ids'] def mtgo_id(self): + if self.__checkForKey('mtgo_id') is None: + return KeyError("This card has no associated mtgo id.") + return self.scryfallJson['mtgo_id'] def mtgo_foil_id(self): + if self.__checkForKey('mtgo_foil_id') is None: + return KeyError("This card has no associate mtgo foil id.") + return self.scryfallJson['mtgo_foil_id'] def name(self): + if self.__checkForKey('name') is None: + return KeyError("This card has no associated name.") + return self.scryfallJson['name'] def uri(self): + if self.__checkForKey('uri') is None: + return KeyError("This card has no associated uri.") + return self.scryfallJson['uri'] def scryfall_uri(self): + if self.__checkForKey('scryfall_uri') is None: + return KeyError("This card has no associated scryfall uri.") + return self.scryfallJson['scryfall_uri'] def layout(self): + if self.__checkForKey('layout') is None: + return KeyError("This card has no associated layout.") + return self.scryfallJson['layout'] def highres_image(self): + if self.__checkForKey('highres_image') is None: + return KeyError("This card has no associated highres image.") + return self.scryfallJson['highres_image'] def image_uris(self): + if self.__checkForKey('image_uris') is None: + return KeyError("This card has no associated image uris.") + return self.scryfallJson['image_uris'] def cmc(self): + if self.__checkForKey('cmc') is None: + return KeyError("This card has no associated cmc.") + return self.scryfallJson['cmc'] def type_line(self): + if self.__checkForKey('type_line') is None: + return KeyError("This card has no associated type line.") + return self.scryfallJson['type_line'] def oracle_text(self): + if self.__checkForKey('oracle_text') is None: + return KeyError("This card has no associated oracle text.") + return self.scryfallJson['oracle_text'] def mana_cost(self): + if self.__checkForKey('mana_cost') is None: + return KeyError("This card has no associated mana cost.") + return self.scryfallJson['mana_cost'] def colors(self): + if self.__checkForKey('colors') is None: + return KeyError("This card has no associated colors.") + return self.scryfallJson['colors'] def color_identity(self): + if self.__checkForKey('color_identity') is None: + return KeyError("This card has no associated color identity.") + return self.scryfallJson['color_identity'] def legalities(self): + if self.__checkForKey('legalities') is None: + return KeyError("This card has no associated legalities.") + return self.scryfallJson['legalities'] + #TODO: Format error def reserved(self): + if self.__checkForKey('reserved') is None: + return KeyError("This card has no associated .") + return self.scryfallJson['reserved'] def reprint(self): + if self.__checkForKey('reprint') is None: + return KeyError("This card has no associated reprint.") + return self.scryfallJson['reprint'] def set(self): + if self.__checkForKey('set') is None: + return KeyError("This card has no associated set.") + return self.scryfallJson['set'] def set_name(self): + if self.__checkForKey('set_name') is None: + return KeyError("This card has no associated set name.") + return self.scryfallJson['set_name'] def set_uri(self): + if self.__checkForKey('set_uri') is None: + return KeyError("This card has no associated set uri.") + return self.scryfallJson['set_uri'] def set_search_uri(self): + if self.__checkForKey('set_search_uri') is None: + return KeyError("This card has no associated set search uri.") + return self.scryfallJson['set_search_uri'] def scryfall_set_uri(self): + if self.__checkForKey('scryfall_set_uri') is None: + return KeyError("This card has no associated scryfall set uri.") + return self.scryfallJson['scryfall_set_uri'] def rulings_uri(self): + if self.__checkForKey('rulings_uri') is None: + return KeyError("This card has no associated rulings uri.") + return self.scryfallJson['rulings_uri'] def prints_search_uri(self): + if self.__checkForKey('prints_search_uri') is None: + return KeyError("This card has no associated prints search uri.") + return self.scryfallJson['prints_search_uri'] def collector_number(self): + if self.__checkForKey('collector_number') is None: + return KeyError("This card has no associated collector number.") + return self.scryfallJson['collector_number'] + #TODO: Format Error def digital(self): + if self.__checkForKey('digital') is None: + return KeyError("This card has no associated .") + return self.scryfallJson['digital'] def rarity(self): + if self.__checkForKey('rarity') is None: + return KeyError("This card has no associated rarity.") + return self.scryfallJson['rarity'] def illustration_id(self): + if self.__checkForKey('illustration_id') is None: + return KeyError("This card has no associated illustration id.") + return self.scryfallJson['illustration_id'] def artist(self): + if self.__checkForKey('artist') is None: + return KeyError("This card has no associated artist.") + return self.scryfallJson['artist'] def frame(self): + if self.__checkForKey('frame') is None: + return KeyError("This card has no associated frame.") + return self.scryfallJson['frame'] + #TODO: Format error def full_art(self): + if self.__checkForKey('') is None: + return KeyError("This card has no associated .") + return self.scryfallJson['full_art'] def border_color(self): + if self.__checkForKey('border_color') is None: + return KeyError("This card has no associated border color.") + return self.scryfallJson['border_color'] + #TODO: Format Error def timeshifted(self): + if self.__checkForKey('timeshifted') is None: + return KeyError("This card has no associated .") + return self.scryfallJson['timeshifted'] + #TODO: Format Error def colorshifted(self): + if self.__checkForKey('colorshifted') is None: + return KeyError("This card has no associated .") + return self.scryfallJson['colorshifted'] + #TODO: Format Error def futureshifted(self): + if self.__checkForKey('futureshifted') is None: + return KeyError("This card has no associated .") + return self.scryfallJson['futureshifted'] def edhrec_rank(self): + if self.__checkForKey('edhrec_rank') is None: + return KeyError("This card has no associated edhrec rank.") + return self.scryfallJson['edhrec_rank'] def currency(self, mode): modes = ['usd', 'eur', 'tix'] if mode not in modes: - return KeyError("That currency is not available.") + return KeyError("This card has no associated currency {}".format(mode)) + + if self.__checkForKey(mode) is None: + return KeyError("This card has no associated currency {}".format(mode)) + return self.scryfallJson[mode] def related_uris(self): + if self.__checkForKey('related_uris') is None: + return KeyError("This card has no associated related uris.") + return self.scryfallJson['related_uris'] def purchase_uris(self): + if self.__checkForKey('purchase_uris') is None: + return KeyError("This card has no associated purchase uris.") + return self.scryfallJson['purchase_uris']