2018-01-25 20:27:56 +00:00
|
|
|
import aiohttp
|
|
|
|
import asyncio
|
2018-02-14 02:02:48 +00:00
|
|
|
import urllib.parse
|
2018-01-25 20:27:56 +00:00
|
|
|
|
2018-02-07 03:01:08 +00:00
|
|
|
class CardsObject(object):
|
2018-01-30 03:32:08 +00:00
|
|
|
def __init__(self, _url, **kwargs):
|
2018-02-14 02:02:48 +00:00
|
|
|
|
|
|
|
self.params = {
|
|
|
|
'format': kwargs.get('format', 'json'), 'face': kwargs.get('face', ''),
|
|
|
|
'version': kwargs.get('version', ''), 'pretty': kwargs.get('pretty', '')
|
|
|
|
}
|
|
|
|
|
|
|
|
self.encodedParams = urllib.parse.urlencode(self.params)
|
|
|
|
self._url = 'https://api.scryfall.com/' + _url + "&" + self.encodedParams #Find a fix for this later
|
2018-01-25 20:27:56 +00:00
|
|
|
|
2018-02-15 20:03:18 +00:00
|
|
|
async def getRequest(client, url, **kwargs):
|
|
|
|
async with client.get(url, **kwargs) as response:
|
2018-01-25 20:27:56 +00:00
|
|
|
return await response.json()
|
|
|
|
|
2018-02-15 20:03:18 +00:00
|
|
|
async def main(loop):
|
|
|
|
async with aiohttp.ClientSession(loop=loop) as client:
|
|
|
|
self.scryfallJson = await getRequest(client, self._url)
|
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.run_until_complete(main(loop))
|
2018-01-30 03:32:08 +00:00
|
|
|
|
|
|
|
if self.scryfallJson['object'] == 'error':
|
|
|
|
raise Exception(self.scryfallJson['details'])
|
|
|
|
|
2018-01-30 04:43:36 +00:00
|
|
|
def __checkForKey(self, key):
|
|
|
|
try:
|
|
|
|
return self.scryfallJson[key]
|
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
def object(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('object') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'object\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['object']
|
|
|
|
|
|
|
|
def id(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('id') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'id\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['id']
|
|
|
|
|
|
|
|
def multiverse_ids(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('multiverse_ids') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'multiverse_ids\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['multiverse_ids']
|
|
|
|
|
|
|
|
def mtgo_id(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('mtgo_id') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'mtgo_id\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['mtgo_id']
|
|
|
|
|
|
|
|
def mtgo_foil_id(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('mtgo_foil_id') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'mtgo_foil_id\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['mtgo_foil_id']
|
|
|
|
|
|
|
|
def name(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('name') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'name\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['name']
|
|
|
|
|
|
|
|
def uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['uri']
|
|
|
|
|
|
|
|
def scryfall_uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('scryfall_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'scryfall_uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['scryfall_uri']
|
|
|
|
|
|
|
|
def layout(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('layout') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'layout\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['layout']
|
|
|
|
|
|
|
|
def highres_image(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('highres_image') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'highres_image\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['highres_image']
|
|
|
|
|
|
|
|
def image_uris(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('image_uris') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'image_uris\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['image_uris']
|
|
|
|
|
|
|
|
def cmc(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('cmc') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'cmc\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['cmc']
|
|
|
|
|
|
|
|
def type_line(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('type_line') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'type_line\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['type_line']
|
|
|
|
|
|
|
|
def oracle_text(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('oracle_text') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'oracle_text\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['oracle_text']
|
|
|
|
|
|
|
|
def mana_cost(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('mana_cost') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'mana_cost\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['mana_cost']
|
|
|
|
|
|
|
|
def colors(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('colors') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'colors\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['colors']
|
|
|
|
|
|
|
|
def color_identity(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('color_identity') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'color_identity\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['color_identity']
|
|
|
|
|
|
|
|
def legalities(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('legalities') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'legalities\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['legalities']
|
|
|
|
|
|
|
|
def reserved(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('reserved') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'reserved\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['reserved']
|
|
|
|
|
|
|
|
def reprint(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('reprint') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'reprint\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['reprint']
|
|
|
|
|
2018-02-07 01:11:18 +00:00
|
|
|
def set_code(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('set') is None:
|
2018-02-14 02:02:48 +00:00
|
|
|
raise KeyError("This card has no key \'set\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['set']
|
|
|
|
|
|
|
|
def set_name(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('set_name') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'set_name\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['set_name']
|
|
|
|
|
|
|
|
def set_uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('set_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'set_uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['set_uri']
|
|
|
|
|
|
|
|
def set_search_uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('set_search_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'set_search_uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['set_search_uri']
|
|
|
|
|
|
|
|
def scryfall_set_uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('scryfall_set_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'scryfall_set_uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['scryfall_set_uri']
|
|
|
|
|
|
|
|
def rulings_uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('rulings_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'rulings_uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['rulings_uri']
|
|
|
|
|
|
|
|
def prints_search_uri(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('prints_search_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'prints_search_uri\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['prints_search_uri']
|
|
|
|
|
|
|
|
def collector_number(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('collector_number') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'collector_number\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['collector_number']
|
|
|
|
|
|
|
|
def digital(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('digital') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'digital\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['digital']
|
|
|
|
|
|
|
|
def rarity(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('rarity') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'rarity\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['rarity']
|
|
|
|
|
|
|
|
def illustration_id(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('illustration_id') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'illustration_id\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['illustration_id']
|
|
|
|
|
|
|
|
def artist(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('artist') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'artist\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['artist']
|
|
|
|
|
|
|
|
def frame(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('frame') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'frame\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['frame']
|
|
|
|
|
|
|
|
def full_art(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'full_art\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['full_art']
|
|
|
|
|
|
|
|
def border_color(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('border_color') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'border_color\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['border_color']
|
|
|
|
|
|
|
|
def timeshifted(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('timeshifted') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'timeshifted\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['timeshifted']
|
|
|
|
|
|
|
|
def colorshifted(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('colorshifted') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'colorshifted\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['colorshifted']
|
|
|
|
|
|
|
|
def futureshifted(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('futureshifted') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'futureshifted\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['futureshifted']
|
|
|
|
|
|
|
|
def edhrec_rank(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('edhrec_rank') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'edhrec_rank\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['edhrec_rank']
|
|
|
|
|
|
|
|
def currency(self, mode):
|
|
|
|
modes = ['usd', 'eur', 'tix']
|
|
|
|
if mode not in modes:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("{} is not a key.".format(mode))
|
2018-01-30 04:43:36 +00:00
|
|
|
|
|
|
|
if self.__checkForKey(mode) is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no currency key {}".format(mode))
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson[mode]
|
|
|
|
|
|
|
|
def related_uris(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('related_uris') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'related_uris\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['related_uris']
|
|
|
|
|
|
|
|
def purchase_uris(self):
|
2018-01-30 04:43:36 +00:00
|
|
|
if self.__checkForKey('purchase_uris') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'purchase_uris\'")
|
2018-01-30 04:43:36 +00:00
|
|
|
|
2018-01-25 20:27:56 +00:00
|
|
|
return self.scryfallJson['purchase_uris']
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
def life_modifier(self):
|
|
|
|
if self.__checkForKey('life_modifier') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'life_modifier\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['life_modifier']
|
|
|
|
|
|
|
|
def hand_modifier(self):
|
|
|
|
if self.__checkForKey('hand_modifier') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'hand_modifier\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['hand_modifier']
|
|
|
|
|
|
|
|
def color_indicator(self):
|
|
|
|
if self.__checkForKey('color_indicator') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'color_indicator\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['color_indicator']
|
|
|
|
|
|
|
|
def all_parts(self):
|
|
|
|
if self.__checkForKey('all_parts') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'all_parts\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['all_parts']
|
|
|
|
|
|
|
|
def card_faces(self):
|
|
|
|
if self.__checkForKey('card_faces') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'card_faces\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['card_faces']
|
|
|
|
|
|
|
|
def watermark(self):
|
|
|
|
if self.__checkForKey('watermark') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'watermark\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['watermark']
|
|
|
|
|
|
|
|
def story_spotlight_number(self):
|
|
|
|
if self.__checkForKey('story_spotlight_number') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'story_spotlight_number\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['story_spotlight_number']
|
|
|
|
|
|
|
|
def story_spotlight_uri(self):
|
|
|
|
if self.__checkForKey('story_spotlight_uri') is None:
|
2018-02-13 21:17:20 +00:00
|
|
|
raise KeyError("This card has no key \'story_spotlight_uri\'")
|
2018-01-30 15:18:47 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['story_spotlight_uri']
|