diff --git a/dbeditingtool.py b/dbeditingtool.py new file mode 100644 index 00000000..330416db --- /dev/null +++ b/dbeditingtool.py @@ -0,0 +1,27 @@ +import requests +import json + +file = open("db.json") +db = json.load(file) +file.close() + +namelist = ["Cosimo03", "fedececco", "Il Gattopardo", "lordlake", "Luzcuzz", "MRdima98", "RYGFrankez", + "Sensei the great", "UnsavouryComb2"] + +for player in namelist: + r = requests.get("https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/" + "{player}?api_key=d2e4cf8f-9a6d-4ce1-8eeb-6342c19f1ae4".format(player=player)) + r = r.json()[player.lower().replace(" ", "")] + lolid = r["id"] + print(str(lolid) + " | " + r["name"]) + discordid = str(input()) + db[discordid] = dict() + db[discordid]["league"] = dict() + db[discordid]["league"]["summonerid"] = lolid + db[discordid]["league"]["region"] = "euw" + db[discordid]["league"]["tier"] = -1 + db[discordid]["league"]["division"] = -1 + +file = open("db.json", "w") +json.dump(db, file) +file.close() diff --git a/league.py b/league.py index 4f96a082..ad512cb9 100644 --- a/league.py +++ b/league.py @@ -29,11 +29,8 @@ async def get_player_rank(region: str, summonerid: int, **kwargs): '/entry?api_key={token}'.format(region=region, summonerid=summonerid, token=token)) # Ensure the request is successful if r.status_code == 200: - if len(r.json()[str(summonerid)]) > 0: - return r.json()[str(summonerid)][0] - else: - raise NoRankedGamesCompletedException("This player hasn't completed any ranked games.") + return r.json()[str(summonerid)][0] elif r.status_code == 404: - raise NotFoundException("Player not found.") + raise NoRankedGamesCompletedException("This player hasn't completed any ranked games.") else: raise Exception("Unhandled API response.") diff --git a/main.py b/main.py index af78a0a5..b86ba523 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ async def overwatch_level_up(timeout): while True: # Wait for the timeout await asyncio.sleep(timeout) + print("Checking for Overwatch updates.") # Update data for every player in list for player in db: if "overwatch" in db[player]: @@ -39,12 +40,14 @@ async def overwatch_level_up(timeout): f = open("db.json", "w") json.dump(db, f) f.close() + print("Check for Overwatch completed.") # Every timeout seconds, update player league and check for rank changes async def league_rank_change(timeout): while True: # Wait for the timeout await asyncio.sleep(timeout) + print("Checking for League of Legends updates.") # Update data for every player in list for player in db: if "league" in db[player]: @@ -58,7 +61,7 @@ async def league_rank_change(timeout): tier_number = league.ranklist.index(r["tier"]) roman_number = league.roman.index(r["entries"][0]["division"]) # Check for tier changes - if tier_number != db[player]["league"]["tier"] or roman_number < db[player]["league"]["division"]: + if tier_number != db[player]["league"]["tier"] or roman_number != db[player]["league"]["division"]: # Convert user ID into a mention user = "<@" + player + ">" # Prepare the message to send @@ -73,9 +76,10 @@ async def league_rank_change(timeout): f = open("db.json", "w") json.dump(db, f) f.close() + print("Check for League of Legends completed.") loop.create_task(overwatch_level_up(900)) -loop.create_task(league_rank_change(120)) +loop.create_task(league_rank_change(5)) try: loop.run_until_complete(d_client.start(token))