Last active
December 11, 2018 11:48
-
-
Save Eskimon/25b08eeb24440acb11d6fb29c236dbd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ids = [ | |
'76561198097653620', # Eskimon | |
'76561197992117520', # Babybel | |
'76561198001774369', # Algrael | |
'' | |
] | |
from bs4 import BeautifulSoup | |
from collections import namedtuple | |
from urllib import request | |
import sys | |
League = namedtuple('League', 'name lvl mmr') | |
Canard = namedtuple('Canard', 'pseudo r1v1 r2v2 r3v3') | |
results = [] | |
ROOT_URL = 'https://rocketleague.tracker.network/profile/steam/{}/' | |
max_name_size = len('pseudo') | |
for c in ids: | |
if not c: | |
continue | |
req = request.Request( | |
ROOT_URL.format(c), | |
data=None, | |
headers={ | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36' | |
} | |
) | |
page = request.urlopen(req).read().decode('utf-8') | |
soup = BeautifulSoup(page, 'html.parser') | |
pseudo = soup.find('h1', class_='name').text.strip().split('\n')[0] | |
last_season = soup.find_all('div', {'class': 'season-table'})[0] | |
table = last_season.find_all('table')[1] | |
ranks = table.find_all('tr') | |
leagues = [] | |
for r in ranks: | |
cells = r.find_all('td') | |
if not cells: | |
continue | |
cat = cells[1].text.strip().replace('\n', ' ') | |
lvl = cat.split(' ')[1] | |
cat = cat.split(' ')[0].lstrip('Ranked ') | |
mmr = cells[3].text.strip().replace('\n', ' ').split()[0] | |
league = League(name=cat, lvl=lvl, mmr=mmr) | |
leagues.append(league) | |
ranks = [0, 0, 0] | |
for l in leagues: | |
if '1v1' in l.name: | |
ranks[0] = l.mmr | |
if '2v2' in l.name: | |
ranks[1] = l.mmr | |
if '3v3' in l.name: | |
ranks[2] = l.mmr | |
results.append(Canard(pseudo=pseudo, r1v1=ranks[0], r2v2=ranks[1], r3v3=ranks[2])) | |
max_name_size = max(max_name_size, len(pseudo)) | |
print('{1: >{0}} | 1v1 | 2v2 | 3v3 |'.format(max_name_size, 'Pseudo', '1v1', '2v2', '3v3')) | |
print('{}+-------+-------+-------+'.format('-'*(max_name_size + 1))) | |
for r in results: | |
print('{1: >{0}} | {2: >5} | {3: >5} | {4: >5} |'.format(max_name_size, r.pseudo, r.r1v1, r.r2v2, r.r3v3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment