mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Added brawlhalla integration
This commit is contained in:
parent
0e972cc792
commit
bb4f8b87a9
2 changed files with 10 additions and 7 deletions
|
@ -7,7 +7,8 @@ loop = asyncio.get_event_loop()
|
||||||
async def get_leaderboard_for(name: str):
|
async def get_leaderboard_for(name: str):
|
||||||
print("[Brawlhalla] Getting leaderboards page for {name}".format(name=name))
|
print("[Brawlhalla] Getting leaderboards page for {name}".format(name=name))
|
||||||
# Get leaderboards page for that 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
|
# Check if the request is successful
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return r
|
return r
|
||||||
|
|
14
main.py
14
main.py
|
@ -157,30 +157,31 @@ async def brawlhalla_update_mmr(timeout):
|
||||||
if "brawlhalla" in db[player]:
|
if "brawlhalla" in db[player]:
|
||||||
try:
|
try:
|
||||||
r = await brawlhalla.get_leaderboard_for(db[player]["brawlhalla"]["username"])
|
r = await brawlhalla.get_leaderboard_for(db[player]["brawlhalla"]["username"])
|
||||||
except Exception:
|
except None:
|
||||||
print("[Brawlhalla] Request returned an unhandled exception.")
|
print("[Brawlhalla] Request returned an unhandled exception.")
|
||||||
else:
|
else:
|
||||||
# Parse the page
|
# Parse the page
|
||||||
bs = bs4.BeautifulSoup(r.text)
|
bs = bs4.BeautifulSoup(r.text, "html.parser")
|
||||||
# Divide the page into rows
|
# Divide the page into rows
|
||||||
rows = bs.find_all("tr")
|
rows = bs.find_all("tr")
|
||||||
# Find the row containing the rank
|
# Find the row containing the rank
|
||||||
for row in rows:
|
for row in rows:
|
||||||
# Skip header rows
|
# Skip header rows
|
||||||
if row['class'] == "rheader":
|
if row.has_attr('id') and row['id'] == "rheader":
|
||||||
continue
|
continue
|
||||||
# Check if the row belongs to the correct player
|
# Check if the row belongs to the correct player
|
||||||
# (Brawlhalla searches aren't case sensitive)
|
# (Brawlhalla searches aren't case sensitive)
|
||||||
for column in row.children:
|
columns = list(row.children)
|
||||||
|
for column in columns:
|
||||||
# Find the player name column
|
# 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
|
# Check if the name matches the parameter
|
||||||
if column.string == db[player]["brawlhalla"]["username"]:
|
if column.string == db[player]["brawlhalla"]["username"]:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
# Get the current mmr
|
# 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
|
# Compare the mmr with the value saved in the database
|
||||||
if mmr != db[player]["brawlhalla"]["mmr"]:
|
if mmr != db[player]["brawlhalla"]["mmr"]:
|
||||||
# Send a message
|
# Send a message
|
||||||
|
@ -193,6 +194,7 @@ async def brawlhalla_update_mmr(timeout):
|
||||||
break
|
break
|
||||||
finally:
|
finally:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
print("[Brawlhalla] Request returned an unhandled exception.")
|
||||||
await asyncio.sleep(timeout)
|
await asyncio.sleep(timeout)
|
||||||
else:
|
else:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
Loading…
Reference in a new issue