2016-08-12 14:40:22 +00:00
|
|
|
import asyncio
|
2016-08-12 14:58:22 +00:00
|
|
|
import requests
|
2016-08-12 15:09:47 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
2016-08-12 14:40:22 +00:00
|
|
|
|
2016-08-12 14:58:22 +00:00
|
|
|
# Get player data
|
|
|
|
async def get_player_data(platform: str, region: str, battletag: str):
|
|
|
|
# Unofficial API requires - for discriminator numbers
|
2016-08-12 15:09:47 +00:00
|
|
|
battletag = battletag.replace("#", "-")
|
2016-08-12 14:58:22 +00:00
|
|
|
# GET the json unofficial API response
|
2016-08-12 15:09:47 +00:00
|
|
|
r = await loop.run_in_executor(None, requests.get,
|
|
|
|
'https://api.lootbox.eu/{platform}/{region}/{battletag}/profile'.format(**locals()))
|
2016-08-12 14:58:22 +00:00
|
|
|
# Ensure the request is successful
|
|
|
|
if r.status_code == 200:
|
|
|
|
return r.json()
|
|
|
|
elif r.status_code == 404:
|
2016-08-12 15:23:45 +00:00
|
|
|
raise Exception("Player not found.")
|