mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 21:44:21 +00:00
Added get_player_data function
This commit is contained in:
parent
ca69cf4244
commit
b5e2a96c73
1 changed files with 15 additions and 2 deletions
15
overwatch.py
15
overwatch.py
|
@ -1,5 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Get player database from the db.json file
|
# Get player database from the db.json file
|
||||||
|
@ -10,3 +10,16 @@ players = list()
|
||||||
for player in db:
|
for player in db:
|
||||||
if player["overwatch"] is not None:
|
if player["overwatch"] is not None:
|
||||||
players.append(player["overwatch"])
|
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.")
|
||||||
|
|
Loading…
Reference in a new issue