Skip to content

Commit

Permalink
Now it doesn't crash on champions with spaces or strange symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
rogama25 committed Feb 2, 2021
1 parent 7ad149c commit de7ef93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion league.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async def connect(connection: Connection):
icon.update_menu()
time.sleep(2)
continue
champ_id = data["selectedChampionId"]
menu_item._text = menu_item._wrap("Randomize")
menu_item._enabled = menu_item._wrap(True)
icon.update_menu()
Expand All @@ -76,7 +77,8 @@ async def connect(connection: Connection):
req = await connection.request("patch", req_type, data=req_data)
data = await req.json()
print("Available", list_skins, skin_names, "Chosen", selected)
easygui.msgbox("Skin selected: " + get_skin_name(selected, skin_names, list_skins), "LoL random skin selector")
easygui.msgbox("Skin selected: " + get_skin_name(selected, skin_names, list_skins, champ_id),
"LoL random skin selector")
time.sleep(1)
except Exception as e:
print(e)
Expand Down
15 changes: 10 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,27 @@ def about():
Version 0.2""",
"LoL random skin selector")

def get_skin_name(selected, skin_names, skin_ids):
def get_skin_name(selected, skin_names, skin_ids, champ_id):
if os.path.exists("./english"):
global version
champ_name = str(skin_names[0])
if champ_name == "Wukong":
champ_name = "MonkeyKing"
champ_name = ""
champ_name_cool = ""
if version is None:
print("Downloading versions...")
versions = requests.get("https://ddragon.leagueoflegends.com/api/versions.json").json()
version = str(versions[0])
all_champ_info = requests.get("http://ddragon.leagueoflegends.com/cdn/11.2.1/data/en_US/champion.json").json()
for champion in all_champ_info["data"]:
if all_champ_info["data"][champion]["key"] == str(champ_id):
champ_name = champion
champ_name_cool = all_champ_info["data"][champion]["name"]
break
print("Getting data for", champ_name)
champ_info = requests.get("http://ddragon.leagueoflegends.com/cdn/" + version +
"/data/en_US/champion/" + champ_name + ".json").json()
for skin in champ_info["data"][champ_name]["skins"]:
if skin["id"] == str(selected):
if skin["name"] == "default":
return champ_name
return champ_name_cool
return skin["name"]
return skin_names[skin_ids.index(selected)]

0 comments on commit de7ef93

Please sign in to comment.