mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Improved lol code
This commit is contained in:
parent
54ae8ff512
commit
be15563ec4
1 changed files with 5 additions and 5 deletions
10
lol.py
10
lol.py
|
@ -16,9 +16,9 @@ tiers = ["BRONZE", "SILVER", "GOLD", "PLATINUM", "DIAMOND", "MASTER", "CHALLENGE
|
||||||
divisions = ["I", "II", "III", "IV", "V"]
|
divisions = ["I", "II", "III", "IV", "V"]
|
||||||
|
|
||||||
|
|
||||||
async def get_json(url, **kwargs):
|
async def get_json(region, endpoint, **kwargs):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(url, **kwargs) as response:
|
async with session.get(f"https://{region.lower()}.api.riotgames.com/api/lol/{region.upper()}{endpoint}", **kwargs) as response:
|
||||||
json = await response.json()
|
json = await response.json()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
raise LoLAPIError(response.status, f"Riot API returned {response.status}")
|
raise LoLAPIError(response.status, f"Riot API returned {response.status}")
|
||||||
|
@ -34,10 +34,10 @@ async def get_summoner_data(region: str, summoner_id=None, summoner_name=None):
|
||||||
"api_key": royalbotconfig.lol_token
|
"api_key": royalbotconfig.lol_token
|
||||||
}
|
}
|
||||||
if summoner_id is not None:
|
if summoner_id is not None:
|
||||||
data = await get_json(f"https://{region.lower()}.api.riotgames.com/api/lol/{region.upper()}/v1.4/summoner/{summoner_id}", params=params)
|
data = await get_json("euw", f"/v1.4/summoner/{summoner_id}", params=params)
|
||||||
return data[str(summoner_id)]
|
return data[str(summoner_id)]
|
||||||
elif summoner_name is not None:
|
elif summoner_name is not None:
|
||||||
data = await get_json(f"https://{region.lower()}.api.riotgames.com/api/lol/{region.upper()}/v1.4/summoner/by-name/{summoner_name}", params=params)
|
data = await get_json("euw", f"/v1.4/summoner/by-name/{summoner_name}", params=params)
|
||||||
return data[summoner_name.lower().replace(" ", "")]
|
return data[summoner_name.lower().replace(" ", "")]
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ async def get_rank_data(region: str, summoner_id: int):
|
||||||
params = {
|
params = {
|
||||||
"api_key": royalbotconfig.lol_token
|
"api_key": royalbotconfig.lol_token
|
||||||
}
|
}
|
||||||
data = await get_json(f"https://{region.lower()}.api.riotgames.com/api/lol/{region.upper()}/v2.5/league/by-summoner/{summoner_id}/entry", params=params)
|
data = await get_json("euw", f"/v2.5/league/by-summoner/{summoner_id}/entry", params=params)
|
||||||
soloq = None
|
soloq = None
|
||||||
flexq = None
|
flexq = None
|
||||||
ttq = None
|
ttq = None
|
||||||
|
|
Loading…
Reference in a new issue