From e1dafb9528670fcafc1290c330a14fc3b0750ae8 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 12 Aug 2016 17:09:47 +0200 Subject: [PATCH] Some bugfixes --- overwatch.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/overwatch.py b/overwatch.py index ed75f38d..6babfd31 100644 --- a/overwatch.py +++ b/overwatch.py @@ -1,6 +1,7 @@ import asyncio import requests import json +loop = asyncio.get_event_loop() # Get player database from the db.json file file = open("db.json") @@ -16,12 +17,14 @@ for player in db: # Get player data async def get_player_data(platform: str, region: str, battletag: str): # Unofficial API requires - for discriminator numbers - battletag.replace("#", "-") + battletag = battletag.replace("#", "-") # GET the json unofficial API response - loop = asyncio.get_event_loop() - r = await loop.run_in_executor(None, requests.get, 'https://api.lootbox.eu/{platform}/{region}/{battletag}/profile') + r = await loop.run_in_executor(None, requests.get, + 'https://api.lootbox.eu/{platform}/{region}/{battletag}/profile'.format(**locals())) # Ensure the request is successful if r.status_code == 200: return r.json() elif r.status_code == 404: raise Exception("Player not found.") + +loop.run_until_complete(get_player_data("pc", "eu", "SteffoRYG#2876"))