From b5e2a96c73d4b3aa796be4c2a1bd14d6d984764c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 12 Aug 2016 16:58:22 +0200 Subject: [PATCH] Added get_player_data function --- overwatch.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/overwatch.py b/overwatch.py index e23bcad2..815a6a88 100644 --- a/overwatch.py +++ b/overwatch.py @@ -1,5 +1,5 @@ import asyncio -import aiohttp +import requests import json # Get player database from the db.json file @@ -9,4 +9,17 @@ db = json.load("db.json") players = list() for player in db: if player["overwatch"] is not None: - players.append(player["overwatch"]) \ No newline at end of file + players.append(player["overwatch"]) + +# Get player data +async def get_player_data(platform: str, region: str, battletag: str): + # Unofficial API requires - for discriminator numbers + 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') + # Ensure the request is successful + if r.status_code == 200: + return r.json() + elif r.status_code == 404: + raise Exception("Player not found.")