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: Example usage:
card = scrython.cards.Autocomplete(query="Ezuri") card = scrython.cards.Autocomplete(query="Ezuri")

View File

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