1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/opendota.py

22 lines
762 B
Python
Raw Normal View History

2016-11-08 18:37:39 +00:00
import asyncio
import requests
2016-12-19 18:56:37 +00:00
import json
2016-11-08 18:37:39 +00:00
loop = asyncio.get_event_loop()
2016-11-08 20:07:23 +00:00
async def get_latest_match(steamidtre: str):
steamidtre = steamidtre[1:-1].split(":")[2]
2016-11-08 18:37:39 +00:00
print("[OpenDota] Getting latest match for: {steamid}".format(steamid=steamidtre))
r = await loop.run_in_executor(None, requests.get, 'https://api.opendota.com/api/players/{steamidtre}/matches?limit=1'.format(steamidtre=steamidtre))
if r.status_code == 200:
pj = r.json()
return pj[0]
else:
raise Exception("OpenDota request error")
2016-12-19 18:56:37 +00:00
def get_hero_name(heroid: int):
j = open("herolist.json", "r")
herolist = json.loads(j.read())
for hero in herolist:
if hero["id"] == heroid:
return hero["localized_name"]
return None