add script
This commit is contained in:
parent
d0cc337280
commit
b227f7d0d1
1 changed files with 91 additions and 0 deletions
91
main.py
Normal file
91
main.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
import requests
|
||||
import pprint
|
||||
|
||||
|
||||
def fetch_mastery_by_username(username):
|
||||
# Riot API dev token
|
||||
headers = {"X-Riot-Token": "RGAPI-37156768-3c38-49fd-b149-1a4adf1fbf66"}
|
||||
|
||||
# Changes based on region
|
||||
base_url = "https://na1.api.riotgames.com"
|
||||
|
||||
# Fetch puuid
|
||||
res = requests.get(
|
||||
f"{base_url}/lol/summoner/v4/summoners/by-name/{username}", headers=headers
|
||||
)
|
||||
|
||||
puuid = res.json()["puuid"]
|
||||
|
||||
# Get champion masteries
|
||||
res = requests.get(
|
||||
f"{base_url}/lol/champion-mastery/v4/champion-masteries/by-puuid/{puuid}",
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
return res.json()
|
||||
|
||||
|
||||
FRACTIONAL_BARS = [
|
||||
" ",
|
||||
"▏",
|
||||
"▎",
|
||||
"▌",
|
||||
"▍",
|
||||
"▋",
|
||||
"▊",
|
||||
"▉",
|
||||
"█",
|
||||
]
|
||||
|
||||
|
||||
def get_bar_from_percentage(percentage):
|
||||
n = percentage * 80
|
||||
|
||||
full_blocks = int(n // 8)
|
||||
partial_blocks = round(n % 8)
|
||||
|
||||
out = "█" * full_blocks
|
||||
out += FRACTIONAL_BARS[partial_blocks]
|
||||
|
||||
return out.ljust(10, " ")
|
||||
|
||||
|
||||
def print_mastery_readout_from_masteries(mastery):
|
||||
points_by_level = {}
|
||||
|
||||
for entry in mastery:
|
||||
level = entry["championLevel"]
|
||||
points = entry["championPoints"]
|
||||
|
||||
points_by_level[level] = points + points_by_level.get(level, 0)
|
||||
|
||||
total = sum(points_by_level.values())
|
||||
|
||||
percentage_by_level = points_by_level.copy()
|
||||
|
||||
for level in points_by_level.keys():
|
||||
percentage_by_level[level] /= total
|
||||
|
||||
percentage_by_level_view = percentage_by_level.items()
|
||||
|
||||
percentage_by_level_view = sorted(percentage_by_level_view, key=lambda x: x[0])
|
||||
|
||||
print(("─" * 13) + "┐")
|
||||
for level, points in reversed(percentage_by_level_view):
|
||||
print(f"{level}: {get_bar_from_percentage(points)}│ {points_by_level[level]}")
|
||||
|
||||
print()
|
||||
|
||||
|
||||
kara_mastery = fetch_mastery_by_username("Heartsii")
|
||||
val_mastery = fetch_mastery_by_username("RavenShade")
|
||||
wyatt_mastery = fetch_mastery_by_username("ColdCut")
|
||||
|
||||
print("Val Mastery\n-------------")
|
||||
print_mastery_readout_from_masteries(val_mastery)
|
||||
|
||||
print("Kara Mastery\n-------------")
|
||||
print_mastery_readout_from_masteries(kara_mastery)
|
||||
|
||||
print("Wyatt Mastery\n-------------")
|
||||
print_mastery_readout_from_masteries(wyatt_mastery)
|
Loading…
Reference in a new issue