From 0520aadad4bcd7dfe624c4c22037a2c95597b32d Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Fri, 16 Feb 2018 20:43:56 -0500 Subject: [PATCH] Created catalog. --- scrython/__init__.py | 13 ++++++ scrython/catalog/__init__.py | 11 ++++++ scrython/catalog/artifact_types.py | 6 +++ scrython/catalog/card_names.py | 6 +++ scrython/catalog/catalogs_object.py | 55 ++++++++++++++++++++++++++ scrython/catalog/creature_types.py | 6 +++ scrython/catalog/land_types.py | 6 +++ scrython/catalog/loyalties.py | 6 +++ scrython/catalog/planeswalker_types.py | 6 +++ scrython/catalog/powers.py | 6 +++ scrython/catalog/spell_types.py | 6 +++ scrython/catalog/toughnesses.py | 6 +++ scrython/catalog/watermarks.py | 6 +++ scrython/catalog/word_bank.py | 6 +++ 14 files changed, 145 insertions(+) create mode 100644 scrython/catalog/__init__.py create mode 100644 scrython/catalog/artifact_types.py create mode 100644 scrython/catalog/card_names.py create mode 100644 scrython/catalog/catalogs_object.py create mode 100644 scrython/catalog/creature_types.py create mode 100644 scrython/catalog/land_types.py create mode 100644 scrython/catalog/loyalties.py create mode 100644 scrython/catalog/planeswalker_types.py create mode 100644 scrython/catalog/powers.py create mode 100644 scrython/catalog/spell_types.py create mode 100644 scrython/catalog/toughnesses.py create mode 100644 scrython/catalog/watermarks.py create mode 100644 scrython/catalog/word_bank.py diff --git a/scrython/__init__.py b/scrython/__init__.py index dd6d5b8..d53fb2c 100644 --- a/scrython/__init__.py +++ b/scrython/__init__.py @@ -17,3 +17,16 @@ from scrython.rulings import Code #Import classes from sets from scrython.sets import Code 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 diff --git a/scrython/catalog/__init__.py b/scrython/catalog/__init__.py new file mode 100644 index 0000000..4d4dcd2 --- /dev/null +++ b/scrython/catalog/__init__.py @@ -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 diff --git a/scrython/catalog/artifact_types.py b/scrython/catalog/artifact_types.py new file mode 100644 index 0000000..ffe7198 --- /dev/null +++ b/scrython/catalog/artifact_types.py @@ -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) diff --git a/scrython/catalog/card_names.py b/scrython/catalog/card_names.py new file mode 100644 index 0000000..18f2c57 --- /dev/null +++ b/scrython/catalog/card_names.py @@ -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) diff --git a/scrython/catalog/catalogs_object.py b/scrython/catalog/catalogs_object.py new file mode 100644 index 0000000..4e74f06 --- /dev/null +++ b/scrython/catalog/catalogs_object.py @@ -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'] diff --git a/scrython/catalog/creature_types.py b/scrython/catalog/creature_types.py new file mode 100644 index 0000000..fad46c5 --- /dev/null +++ b/scrython/catalog/creature_types.py @@ -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) diff --git a/scrython/catalog/land_types.py b/scrython/catalog/land_types.py new file mode 100644 index 0000000..de13df9 --- /dev/null +++ b/scrython/catalog/land_types.py @@ -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) diff --git a/scrython/catalog/loyalties.py b/scrython/catalog/loyalties.py new file mode 100644 index 0000000..e9b6078 --- /dev/null +++ b/scrython/catalog/loyalties.py @@ -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) diff --git a/scrython/catalog/planeswalker_types.py b/scrython/catalog/planeswalker_types.py new file mode 100644 index 0000000..345dc72 --- /dev/null +++ b/scrython/catalog/planeswalker_types.py @@ -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) diff --git a/scrython/catalog/powers.py b/scrython/catalog/powers.py new file mode 100644 index 0000000..1a88efe --- /dev/null +++ b/scrython/catalog/powers.py @@ -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) diff --git a/scrython/catalog/spell_types.py b/scrython/catalog/spell_types.py new file mode 100644 index 0000000..8208752 --- /dev/null +++ b/scrython/catalog/spell_types.py @@ -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) diff --git a/scrython/catalog/toughnesses.py b/scrython/catalog/toughnesses.py new file mode 100644 index 0000000..2d84097 --- /dev/null +++ b/scrython/catalog/toughnesses.py @@ -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) diff --git a/scrython/catalog/watermarks.py b/scrython/catalog/watermarks.py new file mode 100644 index 0000000..8e29d0e --- /dev/null +++ b/scrython/catalog/watermarks.py @@ -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) diff --git a/scrython/catalog/word_bank.py b/scrython/catalog/word_bank.py new file mode 100644 index 0000000..50fd001 --- /dev/null +++ b/scrython/catalog/word_bank.py @@ -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)