From 7e35da05c2d3f285c07876c14c8b380dd8da2803 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Wed, 10 Jan 2018 22:04:03 -0500 Subject: [PATCH 01/13] Added a whole bunch of shit. Also added error handling in creation. --- cards/autocomplete.py | 4 + cards/collector.py | 216 ++++++++++++++++++++++++++++++++++++++++++ cards/id.py | 214 +++++++++++++++++++++++++++++++++++++++++ cards/mtgo.py | 214 +++++++++++++++++++++++++++++++++++++++++ cards/multiverse.py | 214 +++++++++++++++++++++++++++++++++++++++++ cards/named.py | 19 +++- cards/randomcard.py | 212 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1092 insertions(+), 1 deletion(-) create mode 100644 cards/collector.py create mode 100644 cards/id.py create mode 100644 cards/mtgo.py create mode 100644 cards/multiverse.py create mode 100644 cards/randomcard.py diff --git a/cards/autocomplete.py b/cards/autocomplete.py index 18346d1..0e705ec 100644 --- a/cards/autocomplete.py +++ b/cards/autocomplete.py @@ -30,6 +30,10 @@ class Autocomplete(object): url='https://api.scryfall.com/cards/autocomplete?', params={'q':self.query, 'pretty':self.pretty, 'format':self.format})) + if self.scryfallJson['object'] == 'error': + raise Exception(self.scryfallJson['details']) + self.session.close() + self.session.close() def object(self): diff --git a/cards/collector.py b/cards/collector.py new file mode 100644 index 0000000..b51cef3 --- /dev/null +++ b/cards/collector.py @@ -0,0 +1,216 @@ +import asyncio, aiohttp +import json + +class Collector(object): + """ cards/named + + Parameters: + code: int The 3 or 4 letter set code. + collector_number: int The collector number of the card. + format: str The data format to return: json, text, or image. Defaults to json. + face: str If using the image format and this parameter has the value back, + the back face of the card will be returned. + Will return a 404 if this card has no back face. + version: str The image version to return when using the image + format: small, normal, large, png, art_crop, or border_crop. Defaults to large. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + + Attributes: + object: str Returns the type of object it is. (card, error, etc) + id: str The scryfall id of the card. + multiverse_ids: arr The associated multiverse ids of the card. + mtgo_id: int The Magic Online id of the card. + mtgo_foil_id: int The Magic Online foil id of the card. + name: str The full name of the card. Cards with multiple faces are named with '//' as a seperator. + uri: str The Scryfall API uri for the card. + scryfall_uri: str The full Scryfall page of the card. + layout: str The image layout of the card. (normal, transform, etc) + highres_image: bool Returns True if the card has a high res image. + card.image_uris: dict All image uris of the card in various qualities. + cmc: float A float of the converted mana cost of the card. + type_line: str The full type line of the card. + oracle_text: str The official oracle text of a card. + mana_cost: str The full mana cost using shorthanded mana symbols. + colors: arr An array of strings with all colors found in the mana cost. + color_identity: arr An array of strings with all colors found in on the card itself. + legalities: dict A dictionary of all formats and their legality. + reserved: bool Returns True if the card is on the reserved list. + reprint: bool Returns True if the card has been reprinted before. + set: str The 3 letter code for the set of the card. + set_name: str The full name for the set of the card. + set_uri: str The API uri for the full set list of the card. + set_search_uri: str Same output as set_uri. + scryfall_set_uri: str The full link to the set on Scryfall. + rulings_uri: str The API uri for the rulings of the card. + prints_search_uri: str TODO: Figure out what this does. + collector_number: str The collector number of the card. + digital: bool Returns True if the card is the digital version. + rarity: str The rarity of the card. + illustration_id: str The related id of the card art. + artist: str The artist of the card. + frame: str The year of the card frame. + full_art: bool Returns True if the card is considered full art. + border_color: str The color of the card border. + timeshifted: bool Returns True if the card is timeshifted. + colorshifted: bool Returns True if the card is colorshifted. + futureshifted: bool Returns True if the card is futureshifted. + edhrec_rank: int The rank of the card on edhrec.com + tix: int The MTGO price of the card + related_uris: dict A dictionary of related websites for this card. + purchase_uris: dict A dictionary of links to purchase the card. + """ + + def __init__(self, code, collector_number, _format=None, face=None, version=None, pretty=None): + self.code = code + self.collector_number = collector_number + self.format = _format + self.face = face + self.version = version + self.pretty = pretty + loop = asyncio.get_event_loop() + self.session = aiohttp.ClientSession(loop=loop) + + async def getRequest(url, **kwargs): + async with self.session.get(url, **kwargs) as response: + return await response.json() + + self.scryfallJson = loop.run_until_complete(getRequest( + url='https://api.scryfall.com/cards/{}/{}'.format(self.code, self.collector_number), + params={ + 'format':self.format, + 'face':self.face, + 'version':self.version, + 'pretty':self.pretty + })) + + if self.scryfallJson['object'] == 'error': + raise Exception(self.scryfallJson['details']) + self.session.close() + + self.session.close() + + def object(self): + return self.scryfallJson['object'] + + def id(self): + return self.scryfallJson['id'] + + def multiverse_ids(self): + return self.scryfallJson['multiverse_ids'] + + def mtgo_id(self): + return self.scryfallJson['mtgo_id'] + + def mtgo_foil_id(self): + return self.scryfallJson['mtgo_foil_id'] + + def name(self): + return self.scryfallJson['name'] + + def uri(self): + return self.scryfallJson['uri'] + + def scryfall_uri(self): + return self.scryfallJson['scryfall_uri'] + + def layout(self): + return self.scryfallJson['layout'] + + def highres_image(self): + return self.scryfallJson['highres_image'] + + def image_uris(self): + return self.scryfallJson['image_uris'] + + def cmc(self): + return self.scryfallJson['cmc'] + + def type_line(self): + return self.scryfallJson['type_line'] + + def oracle_text(self): + return self.scryfallJson['oracle_text'] + + def mana_cost(self): + return self.scryfallJson['mana_cost'] + + def colors(self): + return self.scryfallJson['colors'] + + def color_identity(self): + return self.scryfallJson['color_identity'] + + def legalities(self): + return self.scryfallJson['legalities'] + + def reserved(self): + return self.scryfallJson['reserved'] + + def reprint(self): + return self.scryfallJson['reprint'] + + def set(self): + return self.scryfallJson['set'] + + def set_name(self): + return self.scryfallJson['set_name'] + + def set_uri(self): + return self.scryfallJson['set_uri'] + + def set_search_uri(self): + return self.scryfallJson['set_search_uri'] + + def scryfall_set_uri(self): + return self.scryfallJson['scryfall_set_uri'] + + def rulings_uri(self): + return self.scryfallJson['rulings_uri'] + + def prints_search_uri(self): + return self.scryfallJson['prints_search_uri'] + + def collector_number(self): + return self.scryfallJson['collector_number'] + + def digital(self): + return self.scryfallJson['digital'] + + def rarity(self): + return self.scryfallJson['rarity'] + + def illustration_id(self): + return self.scryfallJson['illustration_id'] + + def artist(self): + return self.scryfallJson['artist'] + + def frame(self): + return self.scryfallJson['frame'] + + def full_art(self): + return self.scryfallJson['full_art'] + + def border_color(self): + return self.scryfallJson['border_color'] + + def timeshifted(self): + return self.scryfallJson['timeshifted'] + + def colorshifted(self): + return self.scryfallJson['colorshifted'] + + def futureshifted(self): + return self.scryfallJson['futureshifted'] + + def edhrec_rank(self): + return self.scryfallJson['edhrec_rank'] + + def tix(self): + return self.scryfallJson['tix'] + + def related_uris(self): + return self.scryfallJson['related_uris'] + + def purchase_uris(self): + return self.scryfallJson['purchase_uris'] diff --git a/cards/id.py b/cards/id.py new file mode 100644 index 0000000..18b7b69 --- /dev/null +++ b/cards/id.py @@ -0,0 +1,214 @@ +import asyncio, aiohttp +import json + +class Id(object): + """ cards/named + + Parameters: + id: str The Scryfall id of the card. + format: str The data format to return: json, text, or image. Defaults to json. + face: str If using the image format and this parameter has the value back, + the back face of the card will be returned. + Will return a 404 if this card has no back face. + version: str The image version to return when using the image + format: small, normal, large, png, art_crop, or border_crop. Defaults to large. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + + Attributes: + object: str Returns the type of object it is. (card, error, etc) + id: str The scryfall id of the card. + multiverse_ids: arr The associated multiverse ids of the card. + mtgo_id: int The Magic Online id of the card. + mtgo_foil_id: int The Magic Online foil id of the card. + name: str The full name of the card. Cards with multiple faces are named with '//' as a seperator. + uri: str The Scryfall API uri for the card. + scryfall_uri: str The full Scryfall page of the card. + layout: str The image layout of the card. (normal, transform, etc) + highres_image: bool Returns True if the card has a high res image. + card.image_uris: dict All image uris of the card in various qualities. + cmc: float A float of the converted mana cost of the card. + type_line: str The full type line of the card. + oracle_text: str The official oracle text of a card. + mana_cost: str The full mana cost using shorthanded mana symbols. + colors: arr An array of strings with all colors found in the mana cost. + color_identity: arr An array of strings with all colors found in on the card itself. + legalities: dict A dictionary of all formats and their legality. + reserved: bool Returns True if the card is on the reserved list. + reprint: bool Returns True if the card has been reprinted before. + set: str The 3 letter code for the set of the card. + set_name: str The full name for the set of the card. + set_uri: str The API uri for the full set list of the card. + set_search_uri: str Same output as set_uri. + scryfall_set_uri: str The full link to the set on Scryfall. + rulings_uri: str The API uri for the rulings of the card. + prints_search_uri: str TODO: Figure out what this does. + collector_number: str The collector number of the card. + digital: bool Returns True if the card is the digital version. + rarity: str The rarity of the card. + illustration_id: str The related id of the card art. + artist: str The artist of the card. + frame: str The year of the card frame. + full_art: bool Returns True if the card is considered full art. + border_color: str The color of the card border. + timeshifted: bool Returns True if the card is timeshifted. + colorshifted: bool Returns True if the card is colorshifted. + futureshifted: bool Returns True if the card is futureshifted. + edhrec_rank: int The rank of the card on edhrec.com + tix: int The MTGO price of the card + related_uris: dict A dictionary of related websites for this card. + purchase_uris: dict A dictionary of links to purchase the card. + """ + + def __init__(self, _id, _format=None, face=None, version=None, pretty=None): + self.id = _id + self.format = _format + self.face = face + self.version = version + self.pretty = pretty + loop = asyncio.get_event_loop() + self.session = aiohttp.ClientSession(loop=loop) + + async def getRequest(url, **kwargs): + async with self.session.get(url, **kwargs) as response: + return await response.json() + + self.scryfallJson = loop.run_until_complete(getRequest( + url='https://api.scryfall.com/cards/{}'.format(self.id), + params={ + 'format':self.format, + 'face':self.face, + 'version':self.version, + 'pretty':self.pretty + })) + + if self.scryfallJson['object'] == 'error': + raise Exception(self.scryfallJson['details']) + self.session.close() + + self.session.close() + + def object(self): + return self.scryfallJson['object'] + + def id(self): + return self.scryfallJson['id'] + + def multiverse_ids(self): + return self.scryfallJson['multiverse_ids'] + + def mtgo_id(self): + return self.scryfallJson['mtgo_id'] + + def mtgo_foil_id(self): + return self.scryfallJson['mtgo_foil_id'] + + def name(self): + return self.scryfallJson['name'] + + def uri(self): + return self.scryfallJson['uri'] + + def scryfall_uri(self): + return self.scryfallJson['scryfall_uri'] + + def layout(self): + return self.scryfallJson['layout'] + + def highres_image(self): + return self.scryfallJson['highres_image'] + + def image_uris(self): + return self.scryfallJson['image_uris'] + + def cmc(self): + return self.scryfallJson['cmc'] + + def type_line(self): + return self.scryfallJson['type_line'] + + def oracle_text(self): + return self.scryfallJson['oracle_text'] + + def mana_cost(self): + return self.scryfallJson['mana_cost'] + + def colors(self): + return self.scryfallJson['colors'] + + def color_identity(self): + return self.scryfallJson['color_identity'] + + def legalities(self): + return self.scryfallJson['legalities'] + + def reserved(self): + return self.scryfallJson['reserved'] + + def reprint(self): + return self.scryfallJson['reprint'] + + def set(self): + return self.scryfallJson['set'] + + def set_name(self): + return self.scryfallJson['set_name'] + + def set_uri(self): + return self.scryfallJson['set_uri'] + + def set_search_uri(self): + return self.scryfallJson['set_search_uri'] + + def scryfall_set_uri(self): + return self.scryfallJson['scryfall_set_uri'] + + def rulings_uri(self): + return self.scryfallJson['rulings_uri'] + + def prints_search_uri(self): + return self.scryfallJson['prints_search_uri'] + + def collector_number(self): + return self.scryfallJson['collector_number'] + + def digital(self): + return self.scryfallJson['digital'] + + def rarity(self): + return self.scryfallJson['rarity'] + + def illustration_id(self): + return self.scryfallJson['illustration_id'] + + def artist(self): + return self.scryfallJson['artist'] + + def frame(self): + return self.scryfallJson['frame'] + + def full_art(self): + return self.scryfallJson['full_art'] + + def border_color(self): + return self.scryfallJson['border_color'] + + def timeshifted(self): + return self.scryfallJson['timeshifted'] + + def colorshifted(self): + return self.scryfallJson['colorshifted'] + + def futureshifted(self): + return self.scryfallJson['futureshifted'] + + def edhrec_rank(self): + return self.scryfallJson['edhrec_rank'] + + def tix(self): + return self.scryfallJson['tix'] + + def related_uris(self): + return self.scryfallJson['related_uris'] + + def purchase_uris(self): + return self.scryfallJson['purchase_uris'] diff --git a/cards/mtgo.py b/cards/mtgo.py new file mode 100644 index 0000000..e41789f --- /dev/null +++ b/cards/mtgo.py @@ -0,0 +1,214 @@ +import asyncio, aiohttp +import json + +class Mtgo(object): + """ cards/named + + Parameters: + id: int The multiverse id of the card. + format: str The data format to return: json, text, or image. Defaults to json. + face: str If using the image format and this parameter has the value back, + the back face of the card will be returned. + Will return a 404 if this card has no back face. + version: str The image version to return when using the image + format: small, normal, large, png, art_crop, or border_crop. Defaults to large. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + + Attributes: + object: str Returns the type of object it is. (card, error, etc) + id: str The scryfall id of the card. + multiverse_ids: arr The associated multiverse ids of the card. + mtgo_id: int The Magic Online id of the card. + mtgo_foil_id: int The Magic Online foil id of the card. + name: str The full name of the card. Cards with multiple faces are named with '//' as a seperator. + uri: str The Scryfall API uri for the card. + scryfall_uri: str The full Scryfall page of the card. + layout: str The image layout of the card. (normal, transform, etc) + highres_image: bool Returns True if the card has a high res image. + card.image_uris: dict All image uris of the card in various qualities. + cmc: float A float of the converted mana cost of the card. + type_line: str The full type line of the card. + oracle_text: str The official oracle text of a card. + mana_cost: str The full mana cost using shorthanded mana symbols. + colors: arr An array of strings with all colors found in the mana cost. + color_identity: arr An array of strings with all colors found in on the card itself. + legalities: dict A dictionary of all formats and their legality. + reserved: bool Returns True if the card is on the reserved list. + reprint: bool Returns True if the card has been reprinted before. + set: str The 3 letter code for the set of the card. + set_name: str The full name for the set of the card. + set_uri: str The API uri for the full set list of the card. + set_search_uri: str Same output as set_uri. + scryfall_set_uri: str The full link to the set on Scryfall. + rulings_uri: str The API uri for the rulings of the card. + prints_search_uri: str TODO: Figure out what this does. + collector_number: str The collector number of the card. + digital: bool Returns True if the card is the digital version. + rarity: str The rarity of the card. + illustration_id: str The related id of the card art. + artist: str The artist of the card. + frame: str The year of the card frame. + full_art: bool Returns True if the card is considered full art. + border_color: str The color of the card border. + timeshifted: bool Returns True if the card is timeshifted. + colorshifted: bool Returns True if the card is colorshifted. + futureshifted: bool Returns True if the card is futureshifted. + edhrec_rank: int The rank of the card on edhrec.com + tix: int The MTGO price of the card + related_uris: dict A dictionary of related websites for this card. + purchase_uris: dict A dictionary of links to purchase the card. + """ + + def __init__(self, _id, _format=None, face=None, version=None, pretty=None): + self.mtgoid = _id + self.format = _format + self.face = face + self.version = version + self.pretty = pretty + loop = asyncio.get_event_loop() + self.session = aiohttp.ClientSession(loop=loop) + + async def getRequest(url, **kwargs): + async with self.session.get(url, **kwargs) as response: + return await response.json() + + self.scryfallJson = loop.run_until_complete(getRequest( + url='https://api.scryfall.com/cards/mtgo/{}'.format(self.mtgoid), + params={ + 'format':self.format, + 'face':self.face, + 'version':self.version, + 'pretty':self.pretty + })) + + if self.scryfallJson['object'] == 'error': + raise Exception(self.scryfallJson['details']) + self.session.close() + + self.session.close() + + def object(self): + return self.scryfallJson['object'] + + def id(self): + return self.scryfallJson['id'] + + def multiverse_ids(self): + return self.scryfallJson['multiverse_ids'] + + def mtgo_id(self): + return self.scryfallJson['mtgo_id'] + + def mtgo_foil_id(self): + return self.scryfallJson['mtgo_foil_id'] + + def name(self): + return self.scryfallJson['name'] + + def uri(self): + return self.scryfallJson['uri'] + + def scryfall_uri(self): + return self.scryfallJson['scryfall_uri'] + + def layout(self): + return self.scryfallJson['layout'] + + def highres_image(self): + return self.scryfallJson['highres_image'] + + def image_uris(self): + return self.scryfallJson['image_uris'] + + def cmc(self): + return self.scryfallJson['cmc'] + + def type_line(self): + return self.scryfallJson['type_line'] + + def oracle_text(self): + return self.scryfallJson['oracle_text'] + + def mana_cost(self): + return self.scryfallJson['mana_cost'] + + def colors(self): + return self.scryfallJson['colors'] + + def color_identity(self): + return self.scryfallJson['color_identity'] + + def legalities(self): + return self.scryfallJson['legalities'] + + def reserved(self): + return self.scryfallJson['reserved'] + + def reprint(self): + return self.scryfallJson['reprint'] + + def set(self): + return self.scryfallJson['set'] + + def set_name(self): + return self.scryfallJson['set_name'] + + def set_uri(self): + return self.scryfallJson['set_uri'] + + def set_search_uri(self): + return self.scryfallJson['set_search_uri'] + + def scryfall_set_uri(self): + return self.scryfallJson['scryfall_set_uri'] + + def rulings_uri(self): + return self.scryfallJson['rulings_uri'] + + def prints_search_uri(self): + return self.scryfallJson['prints_search_uri'] + + def collector_number(self): + return self.scryfallJson['collector_number'] + + def digital(self): + return self.scryfallJson['digital'] + + def rarity(self): + return self.scryfallJson['rarity'] + + def illustration_id(self): + return self.scryfallJson['illustration_id'] + + def artist(self): + return self.scryfallJson['artist'] + + def frame(self): + return self.scryfallJson['frame'] + + def full_art(self): + return self.scryfallJson['full_art'] + + def border_color(self): + return self.scryfallJson['border_color'] + + def timeshifted(self): + return self.scryfallJson['timeshifted'] + + def colorshifted(self): + return self.scryfallJson['colorshifted'] + + def futureshifted(self): + return self.scryfallJson['futureshifted'] + + def edhrec_rank(self): + return self.scryfallJson['edhrec_rank'] + + def tix(self): + return self.scryfallJson['tix'] + + def related_uris(self): + return self.scryfallJson['related_uris'] + + def purchase_uris(self): + return self.scryfallJson['purchase_uris'] diff --git a/cards/multiverse.py b/cards/multiverse.py new file mode 100644 index 0000000..7c91588 --- /dev/null +++ b/cards/multiverse.py @@ -0,0 +1,214 @@ +import asyncio, aiohttp +import json + +class Multiverse(object): + """ cards/named + + Parameters: + id: int The multiverse id of the card. + format: str The data format to return: json, text, or image. Defaults to json. + face: str If using the image format and this parameter has the value back, + the back face of the card will be returned. + Will return a 404 if this card has no back face. + version: str The image version to return when using the image + format: small, normal, large, png, art_crop, or border_crop. Defaults to large. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + + Attributes: + object: str Returns the type of object it is. (card, error, etc) + id: str The scryfall id of the card. + multiverse_ids: arr The associated multiverse ids of the card. + mtgo_id: int The Magic Online id of the card. + mtgo_foil_id: int The Magic Online foil id of the card. + name: str The full name of the card. Cards with multiple faces are named with '//' as a seperator. + uri: str The Scryfall API uri for the card. + scryfall_uri: str The full Scryfall page of the card. + layout: str The image layout of the card. (normal, transform, etc) + highres_image: bool Returns True if the card has a high res image. + card.image_uris: dict All image uris of the card in various qualities. + cmc: float A float of the converted mana cost of the card. + type_line: str The full type line of the card. + oracle_text: str The official oracle text of a card. + mana_cost: str The full mana cost using shorthanded mana symbols. + colors: arr An array of strings with all colors found in the mana cost. + color_identity: arr An array of strings with all colors found in on the card itself. + legalities: dict A dictionary of all formats and their legality. + reserved: bool Returns True if the card is on the reserved list. + reprint: bool Returns True if the card has been reprinted before. + set: str The 3 letter code for the set of the card. + set_name: str The full name for the set of the card. + set_uri: str The API uri for the full set list of the card. + set_search_uri: str Same output as set_uri. + scryfall_set_uri: str The full link to the set on Scryfall. + rulings_uri: str The API uri for the rulings of the card. + prints_search_uri: str TODO: Figure out what this does. + collector_number: str The collector number of the card. + digital: bool Returns True if the card is the digital version. + rarity: str The rarity of the card. + illustration_id: str The related id of the card art. + artist: str The artist of the card. + frame: str The year of the card frame. + full_art: bool Returns True if the card is considered full art. + border_color: str The color of the card border. + timeshifted: bool Returns True if the card is timeshifted. + colorshifted: bool Returns True if the card is colorshifted. + futureshifted: bool Returns True if the card is futureshifted. + edhrec_rank: int The rank of the card on edhrec.com + tix: int The MTGO price of the card + related_uris: dict A dictionary of related websites for this card. + purchase_uris: dict A dictionary of links to purchase the card. + """ + + def __init__(self, _id, _format=None, face=None, version=None, pretty=None): + self.multiverseid = _id + self.format = _format + self.face = face + self.version = version + self.pretty = pretty + loop = asyncio.get_event_loop() + self.session = aiohttp.ClientSession(loop=loop) + + async def getRequest(url, **kwargs): + async with self.session.get(url, **kwargs) as response: + return await response.json() + + self.scryfallJson = loop.run_until_complete(getRequest( + url='https://api.scryfall.com/cards/multiverse/{}'.format(self.multiverseid), + params={ + 'format':self.format, + 'face':self.face, + 'version':self.version, + 'pretty':self.pretty + })) + + if self.scryfallJson['object'] == 'error': + raise Exception(self.scryfallJson['details']) + self.session.close() + + self.session.close() + + def object(self): + return self.scryfallJson['object'] + + def id(self): + return self.scryfallJson['id'] + + def multiverse_ids(self): + return self.scryfallJson['multiverse_ids'] + + def mtgo_id(self): + return self.scryfallJson['mtgo_id'] + + def mtgo_foil_id(self): + return self.scryfallJson['mtgo_foil_id'] + + def name(self): + return self.scryfallJson['name'] + + def uri(self): + return self.scryfallJson['uri'] + + def scryfall_uri(self): + return self.scryfallJson['scryfall_uri'] + + def layout(self): + return self.scryfallJson['layout'] + + def highres_image(self): + return self.scryfallJson['highres_image'] + + def image_uris(self): + return self.scryfallJson['image_uris'] + + def cmc(self): + return self.scryfallJson['cmc'] + + def type_line(self): + return self.scryfallJson['type_line'] + + def oracle_text(self): + return self.scryfallJson['oracle_text'] + + def mana_cost(self): + return self.scryfallJson['mana_cost'] + + def colors(self): + return self.scryfallJson['colors'] + + def color_identity(self): + return self.scryfallJson['color_identity'] + + def legalities(self): + return self.scryfallJson['legalities'] + + def reserved(self): + return self.scryfallJson['reserved'] + + def reprint(self): + return self.scryfallJson['reprint'] + + def set(self): + return self.scryfallJson['set'] + + def set_name(self): + return self.scryfallJson['set_name'] + + def set_uri(self): + return self.scryfallJson['set_uri'] + + def set_search_uri(self): + return self.scryfallJson['set_search_uri'] + + def scryfall_set_uri(self): + return self.scryfallJson['scryfall_set_uri'] + + def rulings_uri(self): + return self.scryfallJson['rulings_uri'] + + def prints_search_uri(self): + return self.scryfallJson['prints_search_uri'] + + def collector_number(self): + return self.scryfallJson['collector_number'] + + def digital(self): + return self.scryfallJson['digital'] + + def rarity(self): + return self.scryfallJson['rarity'] + + def illustration_id(self): + return self.scryfallJson['illustration_id'] + + def artist(self): + return self.scryfallJson['artist'] + + def frame(self): + return self.scryfallJson['frame'] + + def full_art(self): + return self.scryfallJson['full_art'] + + def border_color(self): + return self.scryfallJson['border_color'] + + def timeshifted(self): + return self.scryfallJson['timeshifted'] + + def colorshifted(self): + return self.scryfallJson['colorshifted'] + + def futureshifted(self): + return self.scryfallJson['futureshifted'] + + def edhrec_rank(self): + return self.scryfallJson['edhrec_rank'] + + def tix(self): + return self.scryfallJson['tix'] + + def related_uris(self): + return self.scryfallJson['related_uris'] + + def purchase_uris(self): + return self.scryfallJson['purchase_uris'] diff --git a/cards/named.py b/cards/named.py index 2bb7e31..5d088b6 100644 --- a/cards/named.py +++ b/cards/named.py @@ -45,7 +45,20 @@ class Named(object): rulings_uri: str The API uri for the rulings of the card. prints_search_uri: str TODO: Figure out what this does. collector_number: str The collector number of the card. - + digital: bool Returns True if the card is the digital version. + rarity: str The rarity of the card. + illustration_id: str The related id of the card art. + artist: str The artist of the card. + frame: str The year of the card frame. + full_art: bool Returns True if the card is considered full art. + border_color: str The color of the card border. + timeshifted: bool Returns True if the card is timeshifted. + colorshifted: bool Returns True if the card is colorshifted. + futureshifted: bool Returns True if the card is futureshifted. + edhrec_rank: int The rank of the card on edhrec.com + tix: int The MTGO price of the card + related_uris: dict A dictionary of related websites for this card. + purchase_uris: dict A dictionary of links to purchase the card. """ def __init__(self, exact=None, fuzzy=None, _set=None, _format=None, face=None, version=None, pretty=None): @@ -75,6 +88,10 @@ class Named(object): 'pretty':self.pretty })) + if self.scryfallJson['object'] == 'error': + self.session.close() + raise Exception(self.scryfallJson['details']) + self.session.close() def object(self): diff --git a/cards/randomcard.py b/cards/randomcard.py new file mode 100644 index 0000000..5ebc23e --- /dev/null +++ b/cards/randomcard.py @@ -0,0 +1,212 @@ +import asyncio, aiohttp +import json + +class RandomCard(object): + """ cards/named + + Parameters: + format: str The data format to return: json, text, or image. Defaults to json. + face: str If using the image format and this parameter has the value back, + the back face of the card will be returned. + Will return a 404 if this card has no back face. + version: str The image version to return when using the image + format: small, normal, large, png, art_crop, or border_crop. Defaults to large. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + + Attributes: + object: str Returns the type of object it is. (card, error, etc) + id: str The scryfall id of the card. + multiverse_ids: arr The associated multiverse ids of the card. + mtgo_id: int The Magic Online id of the card. + mtgo_foil_id: int The Magic Online foil id of the card. + name: str The full name of the card. Cards with multiple faces are named with '//' as a seperator. + uri: str The Scryfall API uri for the card. + scryfall_uri: str The full Scryfall page of the card. + layout: str The image layout of the card. (normal, transform, etc) + highres_image: bool Returns True if the card has a high res image. + card.image_uris: dict All image uris of the card in various qualities. + cmc: float A float of the converted mana cost of the card. + type_line: str The full type line of the card. + oracle_text: str The official oracle text of a card. + mana_cost: str The full mana cost using shorthanded mana symbols. + colors: arr An array of strings with all colors found in the mana cost. + color_identity: arr An array of strings with all colors found in on the card itself. + legalities: dict A dictionary of all formats and their legality. + reserved: bool Returns True if the card is on the reserved list. + reprint: bool Returns True if the card has been reprinted before. + set: str The 3 letter code for the set of the card. + set_name: str The full name for the set of the card. + set_uri: str The API uri for the full set list of the card. + set_search_uri: str Same output as set_uri. + scryfall_set_uri: str The full link to the set on Scryfall. + rulings_uri: str The API uri for the rulings of the card. + prints_search_uri: str TODO: Figure out what this does. + collector_number: str The collector number of the card. + digital: bool Returns True if the card is the digital version. + rarity: str The rarity of the card. + illustration_id: str The related id of the card art. + artist: str The artist of the card. + frame: str The year of the card frame. + full_art: bool Returns True if the card is considered full art. + border_color: str The color of the card border. + timeshifted: bool Returns True if the card is timeshifted. + colorshifted: bool Returns True if the card is colorshifted. + futureshifted: bool Returns True if the card is futureshifted. + edhrec_rank: int The rank of the card on edhrec.com + tix: int The MTGO price of the card + related_uris: dict A dictionary of related websites for this card. + purchase_uris: dict A dictionary of links to purchase the card. + """ + + def __init__(self, _format=None, face=None, version=None, pretty=None): + self.format = _format + self.face = face + self.version = version + self.pretty = pretty + loop = asyncio.get_event_loop() + self.session = aiohttp.ClientSession(loop=loop) + + async def getRequest(url, **kwargs): + async with self.session.get(url, **kwargs) as response: + return await response.json() + + self.scryfallJson = loop.run_until_complete(getRequest( + url='https://api.scryfall.com/cards/random?', + params={ + 'format':self.format, + 'face':self.face, + 'version':self.version, + 'pretty':self.pretty + })) + + if self.scryfallJson['object'] == 'error': + raise Exception(self.scryfallJson['details']) + self.session.close() + + self.session.close() + + def object(self): + return self.scryfallJson['object'] + + def id(self): + return self.scryfallJson['id'] + + def multiverse_ids(self): + return self.scryfallJson['multiverse_ids'] + + def mtgo_id(self): + return self.scryfallJson['mtgo_id'] + + def mtgo_foil_id(self): + return self.scryfallJson['mtgo_foil_id'] + + def name(self): + return self.scryfallJson['name'] + + def uri(self): + return self.scryfallJson['uri'] + + def scryfall_uri(self): + return self.scryfallJson['scryfall_uri'] + + def layout(self): + return self.scryfallJson['layout'] + + def highres_image(self): + return self.scryfallJson['highres_image'] + + def image_uris(self): + return self.scryfallJson['image_uris'] + + def cmc(self): + return self.scryfallJson['cmc'] + + def type_line(self): + return self.scryfallJson['type_line'] + + def oracle_text(self): + return self.scryfallJson['oracle_text'] + + def mana_cost(self): + return self.scryfallJson['mana_cost'] + + def colors(self): + return self.scryfallJson['colors'] + + def color_identity(self): + return self.scryfallJson['color_identity'] + + def legalities(self): + return self.scryfallJson['legalities'] + + def reserved(self): + return self.scryfallJson['reserved'] + + def reprint(self): + return self.scryfallJson['reprint'] + + def set(self): + return self.scryfallJson['set'] + + def set_name(self): + return self.scryfallJson['set_name'] + + def set_uri(self): + return self.scryfallJson['set_uri'] + + def set_search_uri(self): + return self.scryfallJson['set_search_uri'] + + def scryfall_set_uri(self): + return self.scryfallJson['scryfall_set_uri'] + + def rulings_uri(self): + return self.scryfallJson['rulings_uri'] + + def prints_search_uri(self): + return self.scryfallJson['prints_search_uri'] + + def collector_number(self): + return self.scryfallJson['collector_number'] + + def digital(self): + return self.scryfallJson['digital'] + + def rarity(self): + return self.scryfallJson['rarity'] + + def illustration_id(self): + return self.scryfallJson['illustration_id'] + + def artist(self): + return self.scryfallJson['artist'] + + def frame(self): + return self.scryfallJson['frame'] + + def full_art(self): + return self.scryfallJson['full_art'] + + def border_color(self): + return self.scryfallJson['border_color'] + + def timeshifted(self): + return self.scryfallJson['timeshifted'] + + def colorshifted(self): + return self.scryfallJson['colorshifted'] + + def futureshifted(self): + return self.scryfallJson['futureshifted'] + + def edhrec_rank(self): + return self.scryfallJson['edhrec_rank'] + + def tix(self): + return self.scryfallJson['tix'] + + def related_uris(self): + return self.scryfallJson['related_uris'] + + def purchase_uris(self): + return self.scryfallJson['purchase_uris'] From 83df7a53875f4211cb87477e1ebcfd98dbee984a Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Wed, 10 Jan 2018 22:07:15 -0500 Subject: [PATCH 02/13] Updated docstrings of all cards modules. --- cards/collector.py | 4 ++-- cards/id.py | 2 +- cards/mtgo.py | 4 ++-- cards/randomcard.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cards/collector.py b/cards/collector.py index b51cef3..bbc8ad3 100644 --- a/cards/collector.py +++ b/cards/collector.py @@ -2,7 +2,7 @@ import asyncio, aiohttp import json class Collector(object): - """ cards/named + """ cards/:code/:collector_number Parameters: code: int The 3 or 4 letter set code. @@ -82,7 +82,7 @@ class Collector(object): 'version':self.version, 'pretty':self.pretty })) - + if self.scryfallJson['object'] == 'error': raise Exception(self.scryfallJson['details']) self.session.close() diff --git a/cards/id.py b/cards/id.py index 18b7b69..24d88fc 100644 --- a/cards/id.py +++ b/cards/id.py @@ -2,7 +2,7 @@ import asyncio, aiohttp import json class Id(object): - """ cards/named + """ cards/:id Parameters: id: str The Scryfall id of the card. diff --git a/cards/mtgo.py b/cards/mtgo.py index e41789f..5fc2207 100644 --- a/cards/mtgo.py +++ b/cards/mtgo.py @@ -2,10 +2,10 @@ import asyncio, aiohttp import json class Mtgo(object): - """ cards/named + """ cards/mtgo/:id Parameters: - id: int The multiverse id of the card. + id: int The mtgo id of the card. format: str The data format to return: json, text, or image. Defaults to json. face: str If using the image format and this parameter has the value back, the back face of the card will be returned. diff --git a/cards/randomcard.py b/cards/randomcard.py index 5ebc23e..1c79f09 100644 --- a/cards/randomcard.py +++ b/cards/randomcard.py @@ -2,7 +2,7 @@ import asyncio, aiohttp import json class RandomCard(object): - """ cards/named + """ cards/random Parameters: format: str The data format to return: json, text, or image. Defaults to json. @@ -78,7 +78,7 @@ class RandomCard(object): 'version':self.version, 'pretty':self.pretty })) - + if self.scryfallJson['object'] == 'error': raise Exception(self.scryfallJson['details']) self.session.close() From 42db37c69eb812f10bd009da5c10a2dd9d33c994 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Wed, 10 Jan 2018 22:50:10 -0500 Subject: [PATCH 03/13] Added currency attribute to randomcard. --- cards/randomcard.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cards/randomcard.py b/cards/randomcard.py index 1c79f09..c2624ed 100644 --- a/cards/randomcard.py +++ b/cards/randomcard.py @@ -53,7 +53,7 @@ class RandomCard(object): colorshifted: bool Returns True if the card is colorshifted. futureshifted: bool Returns True if the card is futureshifted. edhrec_rank: int The rank of the card on edhrec.com - tix: int The MTGO price of the card + currency: str The various currencies of the card. Modes are usd, eur, tix. related_uris: dict A dictionary of related websites for this card. purchase_uris: dict A dictionary of links to purchase the card. """ @@ -202,8 +202,11 @@ class RandomCard(object): def edhrec_rank(self): return self.scryfallJson['edhrec_rank'] - def tix(self): - return self.scryfallJson['tix'] + def currency(self, mode): + modes = ['usd', 'eur', 'tix'] + if mode not in modes: + return KeyError("That currency is not available.") + return self.scryfallJson[mode] def related_uris(self): return self.scryfallJson['related_uris'] From 344fb532628bf65e5e91506f4c2bb88845b427f8 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Tue, 23 Jan 2018 12:41:56 -0500 Subject: [PATCH 04/13] Removed some naming conflicts and made imports work properly. --- __init__.py | 7 +++++++ cards/__init__.py | 7 +++++++ cards/{id.py => cardid.py} | 0 cards/named.py | 6 +++--- 4 files changed, 17 insertions(+), 3 deletions(-) rename cards/{id.py => cardid.py} (100%) diff --git a/__init__.py b/__init__.py index e69de29..2855c22 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1,7 @@ +from scrython.cards import Autocomplete +from scrython.cards import Collector +from scrython.cards import Id +from scrython.cards import Mtgo +from scrython.cards import Multiverse +from scrython.cards import Named +from scrython.cards import RandomCard diff --git a/cards/__init__.py b/cards/__init__.py index e69de29..08911e0 100644 --- a/cards/__init__.py +++ b/cards/__init__.py @@ -0,0 +1,7 @@ +from .autocomplete import Autocomplete +from .collector import Collector +from .cardid import Id +from .mtgo import Mtgo +from .multiverse import Multiverse +from .named import Named +from .randomcard import RandomCard diff --git a/cards/id.py b/cards/cardid.py similarity index 100% rename from cards/id.py rename to cards/cardid.py diff --git a/cards/named.py b/cards/named.py index 5d088b6..542945e 100644 --- a/cards/named.py +++ b/cards/named.py @@ -14,7 +14,7 @@ class Named(object): Will return a 404 if this card has no back face. version: str The image version to return when using the image format: small, normal, large, png, art_crop, or border_crop. Defaults to large. - pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. Attributes: object: str Returns the type of object it is. (card, error, etc) @@ -27,13 +27,13 @@ class Named(object): scryfall_uri: str The full Scryfall page of the card. layout: str The image layout of the card. (normal, transform, etc) highres_image: bool Returns True if the card has a high res image. - card.image_uris: dict All image uris of the card in various qualities. + card_image_uris: dict All image uris of the card in various qualities. cmc: float A float of the converted mana cost of the card. type_line: str The full type line of the card. oracle_text: str The official oracle text of a card. mana_cost: str The full mana cost using shorthanded mana symbols. colors: arr An array of strings with all colors found in the mana cost. - color_identity: arr An array of strings with all colors found in on the card itself. + color_identity: arr An array of strings with all colors found on the card itself. legalities: dict A dictionary of all formats and their legality. reserved: bool Returns True if the card is on the reserved list. reprint: bool Returns True if the card has been reprinted before. From f7899f11b430f9549f06f311ca2f5c52dc21e6f8 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Thu, 25 Jan 2018 15:27:56 -0500 Subject: [PATCH 05/13] I have no idea what was changed, committing to push. --- .idea/dictionaries/nanda.xml | 15 ++ .idea/inspectionProfiles/Project_Default.xml | 21 ++ .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/scrython.iml | 11 + .idea/vcs.xml | 6 + .idea/workspace.xml | 235 +++++++++++++++++++ cards/named.py | 19 +- cards/randomcard.py | 225 +++++++++--------- cards/scryfall_object.py | 146 ++++++++++++ requirements.txt | 1 + 11 files changed, 570 insertions(+), 121 deletions(-) create mode 100644 .idea/dictionaries/nanda.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scrython.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 cards/scryfall_object.py diff --git a/.idea/dictionaries/nanda.xml b/.idea/dictionaries/nanda.xml new file mode 100644 index 0000000..a902a65 --- /dev/null +++ b/.idea/dictionaries/nanda.xml @@ -0,0 +1,15 @@ + + + + colorshifted + edhrec + futureshifted + highres + mana + mtgo + multiverse + scryfall + timeshifted + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..d34c0a8 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..65531ca --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7535cb7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/scrython.iml b/.idea/scrython.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/scrython.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ab9295e --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python + + + + + PyPep8Inspection + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - 1516750438711 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file