Created catalog.
This commit is contained in:
parent
667cd0d3bb
commit
0520aadad4
|
@ -17,3 +17,16 @@ from scrython.rulings import Code
|
||||||
#Import classes from sets
|
#Import classes from sets
|
||||||
from scrython.sets import Code
|
from scrython.sets import Code
|
||||||
from scrython.sets import Sets
|
from scrython.sets import Sets
|
||||||
|
|
||||||
|
#Import classes from catalogs
|
||||||
|
from scrython.catalog import ArtifactTypes
|
||||||
|
from scrython.catalog import CardNames
|
||||||
|
from scrython.catalog import CreatureTypes
|
||||||
|
from scrython.catalog import LandTypes
|
||||||
|
from scrython.catalog import Loyalties
|
||||||
|
from scrython.catalog import PlaneswalkerTypes
|
||||||
|
from scrython.catalog import Powers
|
||||||
|
from scrython.catalog import SpellTypes
|
||||||
|
from scrython.catalog import Toughnesses
|
||||||
|
from scrython.catalog import Watermarks
|
||||||
|
from scrython.catalog import WordBank
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
from .artifact_types import ArtifactTypes
|
||||||
|
from .card_names import CardNames
|
||||||
|
from .creature_types import CreatureTypes
|
||||||
|
from .land_types import LandTypes
|
||||||
|
from .loyalties import Loyalties
|
||||||
|
from .planeswalker_types import PlaneswalkerTypes
|
||||||
|
from .powers import Powers
|
||||||
|
from .spell_types import SpellTypes
|
||||||
|
from .toughnesses import Toughnesses
|
||||||
|
from .watermarks import Watermarks
|
||||||
|
from .word_bank import WordBank
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class ArtifactTypes(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/artifact-types?'
|
||||||
|
super(ArtifactTypes, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class CardNames(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/card-names?'
|
||||||
|
super(CardNames, self).__init__(self._url)
|
|
@ -0,0 +1,55 @@
|
||||||
|
import asyncio
|
||||||
|
import aiohttp
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
class CatalogsObject(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
|
||||||
|
print(self._url)
|
||||||
|
|
||||||
|
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 uri(self):
|
||||||
|
if self.__checkForKey('uri') is None:
|
||||||
|
raise KeyError('This object has no key \'uri\'')
|
||||||
|
|
||||||
|
return self.scryfallJson['uri']
|
||||||
|
|
||||||
|
def total_values(self):
|
||||||
|
if self.__checkForKey('total_values') is None:
|
||||||
|
raise KeyError('This object has no key \'total_values\'')
|
||||||
|
|
||||||
|
return self.scryfallJson['total_values']
|
||||||
|
|
||||||
|
def data(self):
|
||||||
|
if self.__checkForKey('data') is None:
|
||||||
|
raise KeyError('This object has no key \'data\'')
|
||||||
|
|
||||||
|
return self.scryfallJson['data']
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class CreatureTypes(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/creature-types?'
|
||||||
|
super(CreatureTypes, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class LandTypes(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/land-types?'
|
||||||
|
super(LandTypes, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class Loyalties(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/loyalties?'
|
||||||
|
super(Loyalties, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class PlaneswalkerTypes(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/planeswalker-types?'
|
||||||
|
super(PlaneswalkerTypes, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class Powers(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/powers?'
|
||||||
|
super(Powers, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class SpellTypes(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/spell-types?'
|
||||||
|
super(SpellTypes, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class Toughnesses(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/toughnesses?'
|
||||||
|
super(Toughnesses, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class Watermarks(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/watermarks?'
|
||||||
|
super(Watermarks, self).__init__(self._url)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .catalogs_object import CatalogsObject
|
||||||
|
|
||||||
|
class WordBank(CatalogsObject):
|
||||||
|
def __init__(self):
|
||||||
|
self._url = 'catalog/word-bank?'
|
||||||
|
super(WordBank, self).__init__(self._url)
|
Loading…
Reference in New Issue