Created symbology.

This commit is contained in:
Nanda Scott 2018-02-19 12:20:05 -05:00
parent db1aa0387f
commit bb48c4ca83
5 changed files with 283 additions and 0 deletions

View File

@ -30,3 +30,7 @@ from scrython.catalog import SpellTypes
from scrython.catalog import Toughnesses
from scrython.catalog import Watermarks
from scrython.catalog import WordBank
#Import symbology
from scrython.symbology import ParseMana
from scrython.symbology import Symbology

View File

@ -0,0 +1,2 @@
from .parse_mana import ParseMana
from .symbology import Symbology

View File

@ -0,0 +1,76 @@
from .symbology_object import SymbologyObject
class ParseMana(SymbologyObject):
def __init__(self, **kwargs):
self.cost = kwargs.get('cost')
self.url = 'symbology/parse-mana?cost=' + self.cost
super(ParseMana, self).__init__(self.url)
def __checkForKey(self, key):
try:
return self.scryfallJson[key]
except KeyError:
return None
def object(self):
if self.__checkForKey('object') is None:
raise KeyError('This object has no key \'object\'')
return self.scryfallJson['object']
def mana_cost(self):
if self.__checkForKey('cost') is None:
raise KeyError('This object has no key \'cost\'')
return self.scryfallJson['cost']
def cmc(self):
if self.__checkForKey('cmc') is None:
raise KeyError('This object has no key \'cmc\'')
return self.scryfallJson['cmc']
def colors(self):
if self.__checkForKey('colors') is None:
raise KeyError('This object has no key \'colors\'')
return self.scryfallJson['colors']
def colorless(self):
if self.__checkForKey('colorless') is None:
raise KeyError('This object has no key \'colorless\'')
return self.scryfallJson['colorless']
def monocolored(self):
if self.__checkForKey('monocolored') is None:
raise KeyError('This object has no key \'monocolored\'')
return self.scryfallJson['monocolored']
def multicolored(self):
if self.__checkForKey('multicolored') is None:
raise KeyError('This object has no key \'multicolored\'')
return self.scryfallJson['multicolored']
#The following attributes are only to override the inherited class attributes.
#This class has no matching attributes but we still need the getRequest from SymbologyObject
def appears_in_mana_costs(self):
raise AttributeError('This object has no attribute \'appears_in_mana_costs\'')
def funny(self):
raise AttributeError('This object has no attribute \'funny\'')
def loose_variant(self):
raise AttributeError('This object has no attribute \'loose_variant\'')
def represents_mana(self):
raise AttributeError('This object has no attribute \'represents_mana\'')
def symbol(self):
raise AttributeError('This object has no attribute \'symbol\'')
def transposable(self):
raise AttributeError('This object has no attribute \'transposable\'')

View File

@ -0,0 +1,117 @@
from .symbology_object import SymbologyObject
class Symbology(SymbologyObject):
def __init__(self):
self.url = 'symbology?'
super(Symbology, self).__init__(self.url)
def __checkForKey(self, key):
try:
return self.scryfallJson[key]
except KeyError:
return None
def __checkForTupleKey(self, parent, num, key):
try:
return self.scryfallJson[parent][num][key]
except KeyError:
return None
def object(self):
if self.__checkForKey('object') is None:
raise KeyError('This object has no key \'object\'')
return self.scryfallJson['object']
def has_more(self):
if self.__checkForKey('has_more') is None:
raise KeyError('This object has no key \'has_more\'')
return self.scryfallJson['has_more']
def data(self):
if self.__checkForKey('has_more') is None:
raise KeyError('This object has no key \'data\'')
return self.scryfallJson['data']
def data_length(self):
if self.__checkForKey('data') is None:
return KeyError('This object has no key \'data\'')
return len(self.scryfallJson['data'])
def symbol_symbol(self, num):
if self.__checkForTupleKey('data', num, 'symbol') is None:
raise KeyError('This object has no key \'symbol\'')
return self.scryfallJson['data'][num]['symbol']
def symbol_loose_variant(self, num):
if self.__checkForTupleKey('data', num, 'loose_variant') is None:
raise KeyError('This object has no key \'loose_variant\'')
return self.scryfallJson['data'][num]['loose_variant']
def symbol_transposable(self, num):
if self.__checkForTupleKey('data', num, 'transposable') is None:
raise KeyError('This object has no key \'transposable\'')
return self.scryfallJson['data'][num]['transposable']
def symbol_represents_mana(self, num):
if self.__checkForTupleKey('data', num, 'represents_mana') is None:
raise KeyError('This object has no key \'represents_mana\'')
return self.scryfallJson['data'][num]['represents_mana']
def symbol_cmc(self, num):
if self.__checkForTupleKey('data', num, 'cmc') is None:
raise KeyError('This object has no key \'cmc\'')
return self.scryfallJson['data'][num]['cmc']
def symbol_appears_in_mana_costs(self, num):
if self.__checkForTupleKey('data', num, 'appears_in_mana_costs') is None:
raise KeyError('This object has no key \'appears_in_mana_costs\'')
return self.scryfallJson['data'][num]['appears_in_mana_costs']
def symbol_funny(self, num):
if self.__checkForTupleKey('data', num, 'funny') is None:
raise KeyError('This object has no key \'funny\'')
return self.scryfallJson['data'][num]['funny']
def symbol_colors(self, num):
if self.__checkForTupleKey('data', num, 'colors') is None:
raise KeyError('This object has no key \'colors\'')
return self.scryfallJson['data'][num]['colors']
#The following attributes are only to override the inherited class attributes.
#This class has no matching attributes but we still need the getRequest from SymbologyObject
def symbol(self):
raise AttributeError('This object has no key \'symbol\'')
def loose_variant(self):
raise AttributeError('This object has no key \'loose_variant\'')
def transposable(self):
raise AttributeError('This object has no key \'transposable\'')
def represents_mana(self):
raise AttributeError('This object has no key \'represents_mana\'')
def cmc(self):
raise AttributeError('This object has no key \'cmc\'')
def appears_in_mana_costs(self):
raise AttributeError('This object has no key \'appears_in_mana_costs\'')
def funny(self):
raise AttributeError('This object has no key \'funny\'')
def colors(self):
raise AttributeError('This object has no key \'colors\'')

View File

@ -0,0 +1,84 @@
import asyncio
import aiohttp
import urllib.parse
class SymbologyObject(object):
def __init__(self, _url, **kwargs):
self.params = {'format': kwargs.get('format', 'json'), '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
async def getRequest(client, url, **kwargs):
async with client.get(url, **kwargs) as response:
return await response.json()
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))
if self.scryfallJson['object'] == 'error':
raise Exception(self.scryfallJson['details'])
def __checkForKey(self, key):
try:
return self.scryfallJson[key]
except KeyError:
return None
def object(self):
if self.__checkForKey('object') is None:
raise KeyError('This object has no key \'object\'')
return self.scryfallJson['object']
def symbol(self):
if self.__checkForKey('symbol') is None:
raise KeyError('This object has no key \'symbol\'')
return self.scryfallJson['symbol']
def loose_variant(self):
if self.__checkForKey('loose_variant') is None:
raise KeyError('This object has no key \'loose_variant\'')
return self.scryfallJson['loose_variant']
def transposable(self):
if self.__checkForKey('transposable') is None:
raise KeyError('This object has no key \'transposable\'')
return self.scryfallJson['transposable']
def represents_mana(self):
if self.__checkForKey('represents_mana') is None:
raise KeyError('This object has no key \'represents_mana\'')
return self.scryfallJson['represents_mana']
def cmc(self):
if self.__checkForKey('cmc') is None:
raise KeyError('This object has no key \'cmc\'')
return self.scryfallJson['cmc']
def appears_in_mana_costs(self):
if self.__checkForKey('appears_in_mana_costs') is None:
raise KeyError('This object has no key \'appears_in_mana_costs\'')
return self.scryfallJson['appears_in_mana_costs']
def funny(self):
if self.__checkForKey('funny') is None:
raise KeyError('This object has no key \'funny\'')
return self.scryfallJson['funny']
def colors(self):
if self.__checkForKey('colors') is None:
raise KeyError('This object has no key \'colors\'')
return self.scryfallJson['colors']