From bb4f8b87a935459f07a1cb9e0c4788067b2f8634 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 17 Aug 2016 23:46:58 +0200 Subject: [PATCH] Added brawlhalla integration --- brawlhalla.py | 3 ++- main.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/brawlhalla.py b/brawlhalla.py index 868c7070..2bb1fb6c 100644 --- a/brawlhalla.py +++ b/brawlhalla.py @@ -7,7 +7,8 @@ loop = asyncio.get_event_loop() async def get_leaderboard_for(name: str): print("[Brawlhalla] Getting leaderboards page for {name}".format(name=name)) # Get leaderboards page for that name - r = loop.run_in_executor(None, requests.get, "http://www.brawlhalla.com/rankings/1v1/eu/?p={name}".format(name)) + r = await loop.run_in_executor(None, requests.get, + "http://www.brawlhalla.com/rankings/1v1/eu/?p={name}".format(name=name)) # Check if the request is successful if r.status_code == 200: return r diff --git a/main.py b/main.py index fe6bd7b8..86740f5a 100644 --- a/main.py +++ b/main.py @@ -157,30 +157,31 @@ async def brawlhalla_update_mmr(timeout): if "brawlhalla" in db[player]: try: r = await brawlhalla.get_leaderboard_for(db[player]["brawlhalla"]["username"]) - except Exception: + except None: print("[Brawlhalla] Request returned an unhandled exception.") else: # Parse the page - bs = bs4.BeautifulSoup(r.text) + bs = bs4.BeautifulSoup(r.text, "html.parser") # Divide the page into rows rows = bs.find_all("tr") # Find the row containing the rank for row in rows: # Skip header rows - if row['class'] == "rheader": + if row.has_attr('id') and row['id'] == "rheader": continue # Check if the row belongs to the correct player # (Brawlhalla searches aren't case sensitive) - for column in row.children: + columns = list(row.children) + for column in columns: # Find the player name column - if column['class'] == "pnameleft": + if column.has_attr('class') and column['class'][0] == "pnameleft": # Check if the name matches the parameter if column.string == db[player]["brawlhalla"]["username"]: break else: continue # Get the current mmr - mmr = int(row.children[7].string) + mmr = int(list(row.children)[7].string) # Compare the mmr with the value saved in the database if mmr != db[player]["brawlhalla"]["mmr"]: # Send a message @@ -193,6 +194,7 @@ async def brawlhalla_update_mmr(timeout): break finally: await asyncio.sleep(1) + print("[Brawlhalla] Request returned an unhandled exception.") await asyncio.sleep(timeout) else: await asyncio.sleep(1)