From 9d644e101c3349faa8173ab9098696a6cb6a3bdc Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Wed, 10 Jan 2018 16:55:11 -0500 Subject: [PATCH] Renamed classes and created cards_autocomplete --- {objects => cards}/__init__.py | 0 cards/cards_autocomplete.py | 42 +++++++++++++++++++ .../card_by_name.py => cards/cards_named.py | 5 +-- 3 files changed, 44 insertions(+), 3 deletions(-) rename {objects => cards}/__init__.py (100%) create mode 100644 cards/cards_autocomplete.py rename objects/card_by_name.py => cards/cards_named.py (98%) diff --git a/objects/__init__.py b/cards/__init__.py similarity index 100% rename from objects/__init__.py rename to cards/__init__.py diff --git a/cards/cards_autocomplete.py b/cards/cards_autocomplete.py new file mode 100644 index 0000000..56247cb --- /dev/null +++ b/cards/cards_autocomplete.py @@ -0,0 +1,42 @@ +import asyncio, aiohttp +import json + +class CardsAutocomplete(object): + """ cards/autocomplete + + Parameters: + format: str The data format to return. Currently only supports JSON. + pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. + + Attributes: + object: str Returns the type of object it is. + total_items: int Returns the number of items in data. + data: arr The full autocompleted list. + + """ + + def __init__(self, query, pretty=None, _format=None): + self.query = query + self.pretty = pretty + self.format = _format + loop = asyncio.get_event_loop() + self.session = aiohttp.ClientSession(loop=loop) + + async def getRequest(url, **kwargs): + async with self.session.get(url, **kwargs) as response: + return await response.json() + + self.scryfallJson = loop.run_until_complete(getRequest( + url='https://api.scryfall.com/cards/autocomplete?', + params={'q':self.query, 'pretty':self.pretty, 'format':self.format})) + + self.session.close() + + def object(self): + return self.scryfallJson['object'] + + def total_items(self): + return self.scryfallJson['total_items'] + + def data(self): + return self.scryfallJson['data'] diff --git a/objects/card_by_name.py b/cards/cards_named.py similarity index 98% rename from objects/card_by_name.py rename to cards/cards_named.py index 527f669..de8c890 100644 --- a/objects/card_by_name.py +++ b/cards/cards_named.py @@ -1,8 +1,8 @@ import asyncio, aiohttp import json -class CardByName(object): - """Gets a card by it's name. +class CardsNamed(object): + """ cards/named Attributes: object: str Returns the type of object it is. (card, error, etc) @@ -34,7 +34,6 @@ class CardByName(object): prints_search_uri: str TODO: Figure out what this does. collector_number: str The collector number of the card. - """ def __init__(self, cardname):