Renamed classes and created cards_autocomplete

This commit is contained in:
Nanda Scott 2018-01-10 16:55:11 -05:00
parent 9e5176bcd3
commit 9d644e101c
3 changed files with 44 additions and 3 deletions

View File

@ -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']

View File

@ -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):