Scrython/scrython/sets/sets_object.py

116 lines
3.5 KiB
Python
Raw Normal View History

import sys
sys.path.append('..')
from scrython.foundation import FoundationObject
2018-02-17 00:06:09 +00:00
import asyncio
import aiohttp
import urllib.parse
2018-03-01 02:34:39 +00:00
from threading import Thread
2018-02-17 00:06:09 +00:00
class SetsObject(FoundationObject):
2018-10-22 14:19:38 +00:00
"""
The master class for all sets objects.
2018-02-22 00:00:01 +00:00
2018-10-22 14:19:38 +00:00
Positional arguments:
No arguments required.
2018-02-22 00:00:01 +00:00
2018-10-22 14:19:38 +00:00
Optional arguments:
format : str ................... The format to return. Defaults to JSON.
pretty : bool ... Makes the returned JSON prettier. The library may not work properly with this setting.
2018-02-22 00:00:01 +00:00
2018-10-22 14:19:38 +00:00
Attributes:
object : str ...... Returns the type of object it is. (card, error, etc)
code : str ........................ The three letter set code of the set
mtgo_code : str ........................ The mtgo equivalent of `code()`
name : str ................................... The full name of the set.
set_type : str ......... The type of the set (expansion, commander, etc)
released_at : str ....................... The date the set was launched.
block_code : str ..... The the letter code for the block the set was in.
block : str ................... The full name of the block a set was in.
parent_set_code : str ................. The set code for the parent set.
card_count : int ...................... The number of cards in the set.
digital : bool .............. True if this set is only featured on MTGO.
2018-10-22 14:36:15 +00:00
foil_only : bool ........................... True if this set only has foils.
2018-10-22 14:19:38 +00:00
icon_svg_uri : str ................ A URI to the SVG of the set symbol.
search_uri : str .................. The scryfall API url for the search.
"""
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def _checkForKey(self, key):
if not key in self.scryfallJson:
raise KeyError('This object has no key \'{}\''.format(key))
2018-10-22 14:19:38 +00:00
def _checkForTupleKey(self, parent, num, key):
try:
return self.scryfallJson[parent][num][key]
except Exception:
raise KeyError('This object has no key \'{}\''.format(key))
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def object(self):
self._checkForKey('object')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['object']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def code(self):
self._checkForKey('object')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['code']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def mtgo_code(self):
self._checkForKey('mtgo_code')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['mtgo_code']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def name(self):
self._checkForKey('name')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['name']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def set_type(self):
self._checkForKey('set_type')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['set_type']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def released_at(self):
self._checkForKey('released_at')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['released_at']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def block_code(self):
self._checkForKey('block_code')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['block_code']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def block(self):
self._checkForKey('block')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['block']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def parent_set_code(self):
self._checkForKey('parent_set_code')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['parent_set_code']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def card_count(self):
self._checkForKey('card_count')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['card_count']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def digital(self):
self._checkForKey('digital')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['digital']
2018-02-17 00:06:09 +00:00
2018-10-22 14:36:15 +00:00
def foil_only(self):
self._checkForKey('foil_only')
2018-02-17 00:06:09 +00:00
2018-10-22 14:36:15 +00:00
return self.scryfallJson['foil_only']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def icon_svg_uri(self):
self._checkForKey('icon_svg_uri')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['icon_svg_uri']
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
def search_uri(self):
self._checkForKey('search_uri')
2018-02-17 00:06:09 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['search_uri']