1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/overwatch.py

28 lines
846 B
Python
Raw Normal View History

2016-08-12 14:40:22 +00:00
import asyncio
2016-08-12 14:58:22 +00:00
import requests
2016-08-12 14:40:22 +00:00
import json
# Get player database from the db.json file
2016-08-12 15:03:54 +00:00
file = open("db.json")
db = json.load(file)
file.close()
2016-08-12 14:40:22 +00:00
# List overwatch players
players = list()
for player in db:
2016-08-12 15:03:54 +00:00
if db[player]["overwatch"] is not None:
players.append(db[player]["overwatch"])
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
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.")