I think I fixed the issue with async now.

This commit is contained in:
Nanda Scott 2018-02-15 15:03:18 -05:00
parent b042679f36
commit 1177ebaf46
2 changed files with 8 additions and 10 deletions

View File

@ -120,5 +120,3 @@ Get a list of potential autocompletion phrases.
Example usage:
card = scrython.cards.Autocomplete(query="Ezuri")

View File

@ -12,21 +12,21 @@ class CardsObject(object):
self.encodedParams = urllib.parse.urlencode(self.params)
self._url = 'https://api.scryfall.com/' + _url + "&" + self.encodedParams #Find a fix for this later
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:
async def getRequest(client, url, **kwargs):
async with client.get(url, **kwargs) as response:
return await response.json()
self.scryfallJson = loop.run_until_complete(getRequest(url = self._url))
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':
self.session.close()
raise Exception(self.scryfallJson['details'])
self.session.close()
def __checkForKey(self, key):
try:
return self.scryfallJson[key]